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>