Colleagues in the project using the scroll event to load data, the result of IE tragedy. A simple optimization method is given, and the effect is obvious.
As long as the user changes the window size, the internal element size will be recalculated, which may cause the entire page to be rendered again, resulting in a large amount of CPU consumption. For example, call resize method, the user changes the window will be constantly triggered, the lower version of IE may fall into suspended animation state. Window Scroll event is also the case, the mouse scroll or drag the scroll bar, will not stop the trigger scroll events, if the processing of more things, the lower version of IE will also fall into suspended animation state.
Basic idea of optimization: within a certain period of time, only one Resize event function is executed.
Copy Code code as follows:
var resizetimer = null;
$ (window). On (' Resize ', function () {
if (Resizetimer) {
Cleartimeout (Resizetimer)
}
Resizetimer = settimeout (function () {
Console.log ("Window resize");
}, 400);
}
);
Scroll event optimization is similarly.