javascript性能最適化-repaintとreflow
4474 ワード
repaint( ) ,repaint , , , outline,visibility,background color, dom 。 reflow( ), repaint dom , repaint, ( ), , , 。 、 : 1. DOM 、 ( )、 ( Reflow + Repaint) 2. DOM ( Repaint, ) 3. 4. Resize 、 5. (offsetLeft、offsetTop、offsetHeight、offsetWidth、 scrollTop/Left/Width/Height、clientTop/Left/Width/Height、 getComputedStyle()、currentStyle(in IE)) -- bootstrap.js xx.offsetHeight/xx.offsetWidth force reflow 、 : 1. document , 2. display ”none”, display 3. DOM , DocumentFragment document var fragment = document.createDocumentFragment(); fragment.appendChild(document.createTextNode('keenboy test 111')); fragment.appendChild(document.createElement('br')); fragment.appendChild(document.createTextNode('keenboy test 222')); document.body.appendChild(fragment); 4. 4.1 style 4.2 className 4.3 cssText element.style.width=”80px”; //reflow
element.style.height=”90px”; //reflow
element.style.border=”solid 1px red”; //reflow
reflow, element.style.cssText=”width:80px;height:80px;border:solid 1px red;”; //reflow
4.4 Layout var left=elem.offsetLeft; left reflow 4.5 position absolute fixed , DOM , reflow reflow 4.6 table table reflow table reflow。 table , table-layout auto fixed, table , reflow 4.7 expression, ( ) : Yahoo! Nicole Sullivan 《Reflows & Repaints: CSS Performance making your JavaScript slow?》