IE7 browser window size change event execution multiple times bug and IE6/IE7/IE8 resize problem _ jquery

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.