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

原文地址:https://www.cnblogs.com/yy-hh/p/4739443.html