1. What is Reflow?
Reflow (reflow) refers to the process by which a browser recalculates the position and geometry of elements in a document in order to re-render some or all of the documents.
Because reflux can cause the entire DOM tree to be reconstructed, it is a major killer of performance.
The following operations can cause reflux:
① changing window size
②font-size size Change
③ Add or remove style sheets
④ content changes (input text will cause)
⑤ activating CSS Pseudo-class (: hover)
⑥ Operation class attribute, new or reduced
⑦js manipulating the DOM
⑧offset Correlation Property Calculation
⑨ setting the value of a style
......
Reflow and repaint are some of the main reasons to slow JS, especially reflow is a performance killer, so we should try to avoid.
<style type= "Text/css" >. changestyle {width:100px; height:100px;}</style><script type= "Text/javascript" >$ (document). Ready (function () { varEl = $ (' ID '); //1El.css (' width ', ' 100px '); El.css (' Height ', ' 100px '); //2El.css ({' width ': ' 100px; ', ' height ': ' 100px; ') }); //3El.addclass (' Changestyle '); });</script>
Recommend the third, avoid the first type of
The above several practices, I here weak weak recommendation of the third, avoid the first kind.
② Animated effect please use absolute
Because the change of the absolute element has little effect on the reflux of other elements, the elements of our animated effect still make him into a absolute.
③ Avoid using table layouts (remember that it's just the layout, we should use the table)
④ please never use CSS expressions, performance killers, especially IE
⑤ at the last change element
Because the reflux is top-down, so it is not up to the bottom, we change the information on the last side of the overall impact less.
⑥ animation when moving, to control
For example, when we drag an element, I change the x or Y coordinate of 5px to operate, which reduces the smoothness, but improves performance.
Reflow of Web front-end optimization (reduce reflow of pages)