简体   繁体   English

使用javascript访问浏览器的页面缩放控件

[英]Access browser's page zoom controls with javascript

I want to assign the browser's (IE/FF) page zoom controls (Menu: View/Zoom/Zoom In_Zoom Out) to two large "(+)(-)" icons on the web page so that vision impaired visitors can use these controls conveniently. 我想将浏览器的 (IE / FF) 页面缩放控件(菜单:查看/缩放/缩放In_Zoom输出)分配给网页上的两个大“(+)( - )”图标,以便视障人士可以使用这些控件方便。

A lot of searching for a suitable script came up empty so here I am. 很多搜索合适的脚本都空了,所以我在这里。

Any code you know that will do this simply? 您知道的任何代码都可以做到这一点吗?

All the best... 祝一切顺利...

Bob 短发

You should be able to set the CSS3 Transform property using JavaScript to scale content. 您应该能够使用JavaScript设置CSS3 Transform属性来scale内容。 This won't be tied to the web browser zoom functionality though. 这不会与Web浏览器缩放功能相关联。

Can't be done at all as far as I know. 据我所知,根本无法完成。 As has been discussed elsewhere on SO, it is possible to detect the browser's zoom level using a number of tricks. 正如在SO上的其他地方所讨论的那样,可以使用许多技巧来检测浏览器的缩放级别。 There's no way to set them from plain JavaScript. 没有办法从纯JavaScript中设置它们。

Maybe in a Firefox extension. 也许在Firefox扩展中。

Related: 有关:

This is how I do something similar in jQuery: 这就是我在jQuery中做类似的事情:

I made it up last night and tested on IE7, IE8, FF3.6, Safari 5, Chrome 10, and more. 我昨晚做了,并在IE7,IE8,FF3.6,Safari 5,Chrome 10等测试。

I have a banner that overflows when people zoom out on some browsers. 当人们缩小某些浏览器时,我有一个横幅溢出。 So I check the width of my .nav. 所以我检查了我的.nav的宽度。 If it wraps it will be shorter that its full width. 如果它包裹它将比它的全宽更短。

   $(function() {

        //launch doZoomCheck on load
        doZoomCheck();

        $(window).resize(function() {
            // .resize ALSO fires when people change the zoom of their browser.
            doZoomCheck();
        });

        function doZoomCheck() {
              var width = $(".nav ul").width();
              // if the width of the banner isn't near 976 is prolly overflowing
              if ( width > 976) {
                     // change to narrow font so menu doesn't wrap funny
                     $(".nav ul li a, #footer .frankmed").css("font-family", "Arial Narrow");
              }
                 // if width is back to normal change the font back
              if ( width < 976) {
                 // remove special styles when zoomed back out
             $(".nav ul li a").attr('style','');
             }
        }
  });

I'm using jQuery 1.5, prolly works back to 1.3.2 but haven't checked. 我正在使用jQuery 1.5,可以回溯到1.3.2,但还没有检查过。

Please note: My font size is 20px already so Arial Narrow is very legible at that size. 请注意:我的字体大小已经是20px,因此Arial Narrow在这个尺寸上非常清晰。 I am not stopping the user from changing the font size. 我没有阻止用户更改字体大小。 I am not overriding it. 我没有压倒它。 I am just changing a font. 我只是改变一种字体。 Do not use this script for evil. 不要将此脚本用于恶意。 Don't be stupid. 别傻了。 Accessibility is important. 可访问性很重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM