简体   繁体   中英

I have two buttons when i click on plus button the web page has to zoom in and click on minus button to zoom out .click on other button to default

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 + '%');
    }
});

I have used this code in Javascript , it is not working. Can i get any ideas regarding this requirement ?

I have two buttons when I click on plus button the web page has to zoom in and a click on minus button to zoom out and a click on other button to default.

I have changed your code slightly to correct a couple of things. The MozTransform CSS property should be -moz-transform instead. I have also removed a couple of unnecessary spaces you were adding to the property value:

var currFFZoom = 1;
var currIEZoom = 100;

$('#plusBtn').on('click',function(){
    if ($.browser.mozilla){
        var step = 0.02;
        currFFZoom += step; 
        $('body').css('-moz-transform', '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('-moz-transform', 'scale(' + currFFZoom + ')');

    } else {
        var step = 2;
        currIEZoom -= step;
        $('body').css('zoom', currIEZoom + '%');
    }
});

See it here working: fiddle .

Edit 1

I had left some alerts in the code but just removed them. Also explained the changes I did in your code.

Edit 2

Beware that $.browser is deprecated and should be used with care or alternatively replaced with Feature & Browser Detection .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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