IE6/IE7/IE8 JQuery下resize事件执行多次的解决方法

在使用jQuery的resize事件时发现每次改变浏览器的窗口大小时resize时间会执行两次,百度搜索了一下找到一个解决的方法,使用setTimeout来解决这个问题代码如下:

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++;
});
原文地址:https://www.cnblogs.com/dtdxrk/p/3678267.html