Multiple executions in onresize IE

Source: Internet
Author: User

On the page, define the onresize event for the window object. When the window is scaled out, the onresize method is executed multiple times, affecting the page performance.
I checked some information on the Internet, saying that in ie and opera, the resize event is triggered as long as the border of the window moves a pixel. in mozilla, the resize event is triggered only when the size of the window is changed.
It is ideal to trigger the resize event when the window size is changed.

I think the onresize trigger is like this: according to a short interval, when you drag the window of 200*200 to 200*400, it takes several times to resize, this triggers several onresize.

To avoid the adverse effects of multiple onresize triggers that may cause multiple code executions, you can write a function and call the code you want to execute after onresize interval (setTimeout, you can set the status variable to determine whether to execute the task. If the interval between two onresize operations is less than 100 ms, you can use setTimeout.

<Script type = "text/javascript">
Var resizeTimer = null;
Function doResize (){
Alert ("width =" Your document.doc umentElement. clientWidth + "Height =" Your document.doc umentElement. clientHeight );
ResizeTimer = null
}
Window. onresize = function (){
If (resizeTimer = null ){
ResizeTimer = setTimeout ("doResize ()", 300 );
}
}
</Script>

Related Article

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.