开发者

ResizeStop without namespace pollution

开发者 https://www.devze.com 2023-02-07 03:21 出处:网络
I\'m trying to detect when the browser has stopped being resized. The following works, but depends on global vars. Isn\'t there a way to use closures to avoid this? If so, how?开发者_如何学Go

I'm trying to detect when the browser has stopped being resized. The following works, but depends on global vars. Isn't there a way to use closures to avoid this? If so, how?开发者_如何学Go

    var rtime = new Date(1, 1, 2000, 12,00,00);
    var timeout = false;
    var delta = 200;

    $(document).ready(function() {          

        $(window).resize(function() {
            rtime = new Date();
            if (timeout === false) {
                timeout = true;
                setTimeout(resizeend, delta);
            }
        });

    });

    function resizeend() {
        if (new Date() - rtime < delta) {
            setTimeout(resizeend, delta);
        } else {
            timeout = false;
            $("#log").append("<span>resizeend</span> ");
        }               
    }

** Script credit: http://vidasp.net/resizeend.html


(function(){ 
var rtime = new Date(1, 1, 2000, 12,00,00);
var timeout = false;
var delta = 200;

$(document).ready(function() {          

    $(window).resize(function() {
        rtime = new Date();
        if (timeout === false) {
            timeout = true;
            setTimeout(resizeend, delta);
        }
    });

});

function resizeend() {
    if (new Date() - rtime < delta) {
        setTimeout(resizeend, delta);
    } else {
        timeout = false;
        $("#log").append("<span>resizeend</span> ");
    }               
}
})();

Is a closure

0

精彩评论

暂无评论...
验证码 换一张
取 消