Fork me on GitHub

IE7浏览器窗口大小改变事件执行多次bug(转)

var resizeTimer = null;
$(window).resize(function() {
    if (resizeTimer) clearTimeout(resizeTimer);
    resizeTimer = setTimeout("alert('mm')", 500);
});

 

 

还有一个通过判断变量的奇偶来解决(感觉这方法还行),代码如下:

复制代码
var n=0;
$(window).resize(function(){
    if(n%2==0){
        alert("mm");
    }
    n++;
});

无论是jquery封装的还是js原生的都会产生此bug

posted @ 2015-08-21 09:37  野路子PM  阅读(457)  评论(0编辑  收藏  举报