Changing the browser zoom level

后端 未结 8 1709
野的像风
野的像风 2020-11-22 07:00

I have need to create 2 buttons on my site that would change the browser zoom level (+) (-). I\'m requesting browser zoom and not css zoom because of image size and layout i

8条回答
  •  一整个雨季
    2020-11-22 07:18

    Try if this works for you. This works on FF, IE8+ and chrome. The else part applies for non-firefox browsers. Though this gives you a zoom effect, it does not actually modify the zoom value at browser level.

        var currFFZoom = 1;
        var currIEZoom = 100;
    
        $('#plusBtn').on('click',function(){
            if ($.browser.mozilla){
                var step = 0.02;
                currFFZoom += step; 
                $('body').css('MozTransform','scale(' + currFFZoom + ')');
            } else {
                var step = 2;
                currIEZoom += step;
                $('body').css('zoom', ' ' + currIEZoom + '%');
            }
        });
    
        $('#minusBtn').on('click',function(){
            if ($.browser.mozilla){
                var step = 0.02;
                currFFZoom -= step;                 
                $('body').css('MozTransform','scale(' + currFFZoom + ')');
    
            } else {
                var step = 2;
                currIEZoom -= step;
                $('body').css('zoom', ' ' + currIEZoom + '%');
            }
        });
    

提交回复
热议问题