簡體   English   中英

當我單擊加號按鈕時,我有兩個按鈕,網頁必須放大,然后單擊減號按鈕以縮小。單擊其他按鈕以默認

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

我已經在Javascript使用了此代碼,但無法正常工作。 我可以對此要求有任何想法嗎?

當我單擊加號按鈕時,我有兩個按鈕,網頁必須放大,單擊減號按鈕以縮小,單擊其他按鈕為默認按鈕。

我已經稍微更改了您的代碼,以更正了幾件事。 MozTransform CSS屬性應改為-moz-transform 我還刪除了您在屬性值中添加的一些不必要的空格:

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

看到這里工作: 小提琴

編輯1

我在代碼中留下了一些警報,但只是刪除了它們。 還解釋了我在代碼中所做的更改。

編輯2

注意$.browser過時 ,應謹慎使用,或用Feature&Browser Detection代替。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM