This article mainly introduces the issue of executing multiple bugs in IE7 browser window size change events and the resize issue in IE6IE7IE8, if you need it, you can learn it together. This article mainly uses code examples to introduce the issue of multiple bugs in executing Windows size change events in IE7 and the issue of resize in IE6/IE7/IE8. step-by-step introduction, this section describes how to execute multiple bugs in the IE7 browser window size change event. For more information about the problem analysis and solution, see the following.
var resizeTimer = null;$(window).resize(function() { if (resizeTimer) clearTimeout(resizeTimer); resizeTimer = setTimeout("alert('mm')", 500);});
Another solution is to judge the parity of the variable (I feel this method is okay)
The code is as follows:
var n=0;$(window).resize(function(){ if(n%2==0){ alert("mm"); } n++;});
This bug occurs both in jquery encapsulation and in js native versions.
Solution for executing the resize event multiple times in IE6, IE7, and IE8 JQuery
When using the jQuery resize event, it is found that every time the browser window is changed, the resize time will be executed twice. baidu searched for a solution,
The following code uses setTimeout to solve this problem:
var resizeTimer = null;$(window).resize(function() { if (resizeTimer) clearTimeout(resizeTimer); resizeTimer = setTimeout("alert('mm')", 500);});
There is also a solution by judging the parity of the variable (I feel this method is okay), the code is as follows:
var n=0;$(window).resize(function(){ if(n%2==0){ alert("mm"); } n++;});
The above is the bug in executing the window size change event in IE7 and the resize issue in IE6, IE7, and IE8. I hope it will be helpful to you.