[·Òë]High Performance JavaScript(011)
Repaints and Reflows ÖØ»æºÍÖØÅÅ°æ
Once the browser has downloaded all the components of a page—HTML markup, JavaScript, CSS, images—it parses through the files and creates two internal data structures:
µ±ä¯ÀÀÆ÷ÏÂÔØÍêËùÓÐÒ³ÃæHTML±ê¼Ç£¬JavaScript£¬CSS£¬Í¼Æ¬Ö®ºó£¬Ëü½âÎöÎļþ²¢´´½¨Á½¸öÄÚ²¿Êý¾Ý½á¹¹£º
A DOM tree
A representation of the page structure
Ò»¿ÃDOMÊ÷
±íʾҳÃæ½á¹¹
A render tree
A representation of how the DOM nodes will be displayed
Ò»¿ÃäÖȾÊ÷
±íʾDOM½ÚµãÈçºÎÏÔʾ
The render tree has at least one node for every node of the DOM tree that needs to be displayed (hidden DOM elements don't have a corresponding node in the render tree). Nodes in the render tree are called frames or boxes in accordance with the CSS model that treats page elements as boxes with padding, margins, borders, and position. Once the DOM and the render trees are constructed, the browser can display ("paint") the elements on the page.
äÖȾÊ÷ÖÐΪÿ¸öÐèÒªÏÔʾµÄDOMÊ÷½Úµã´æ·ÅÖÁÉÙÒ»¸ö½Úµã£¨Òþ²ØDOMÔªËØÔÚäÖȾÊ÷ÖÐûÓжÔÓ¦½Úµã£©¡£äÖȾÊ÷ÉϵĽڵã³ÆΪ“¿ò”»òÕß“ºÐ”£¬·ûºÏCSSÄ£Ð͵Ķ¨Ò壬½«Ò³ÃæÔªËØ¿´×÷Ò»¸ö¾ßÓÐÌî³ä¡¢±ß¾à¡¢±ß¿òºÍλÖõĺС£Ò»µ©DOMÊ÷ºÍäÖȾÊ÷¹¹ÔìÍê±Ï£¬ä¯ÀÀÆ÷¾Í¿ÉÒÔÏÔʾ£¨»æÖÆ£©Ò³ÃæÉϵÄÔªËØÁË¡£
When a DOM change affects the geometry of an element (width and height)—such as a change in the thickness of the border or adding more text to a paragraph, resulting in an additional line—the browser needs to recalculate the geometry of the element as well as the geometry and position of other elements that could have been affected by the change. The browser invalidates the part of the render tree that was affected by the change and reconstructs the render tree. This process is known as a reflow. Once the reflow is complete, the browser redraws the affected parts of the screen in a
Ïà¹ØÎĵµ£º
±¾ÎÄÖ÷ÒªÊdzöÓÚÓÐÅóÓÑʹÓÃÎÒÔÀ´Ð´µÄautocompleteµÄJS¿Ø¼þ¡£µ±Êý¾ÝÁ¿´óµÄʱºò£¬»á³öÏÖЧÂʼ«ÆäÂýµÄÇé¿ö£¬ÎÒÔÚÕâ¶Îʱ¼ä×ö³öµÄһЩ²âÊÔÒ²¼°Ò»Ð©¾Ñ飬Óë´ó¼Ò·ÖÏí£¬Èç¹ûÓдíµÄµØ·½£¬»¹ÇëÖ¸³ö¡£
¾¹ý²âÊÔ£¬ÎÒÃǻᷢÏÖÈçϵÄÇé¿ö»òÕß˵µÄ½áÂÛ£¬Èç¹ûÄúµÄ²âÊÔ½á¹ûÓëÎҵIJ»·û£¬Çë˵Ã÷ÔÒò£¬ÒÔ±ãÏ໥ѧϰ¡£
1£©µ±Ò»¸ö½Ï´óµÄHTML×Ö· ......
£¼script language="javaScript"£¾
function closeWindow()
{
¡¡window.opener = null;
¡¡window.open(' ', '_self', ' ');
¡¡window.close();
}
£¼/script£¾
£¼input type='button' value='¹Ø±Õ´°¿Ú' onClick="closeWindow()"£¾
»ò
£¼input type="button" value="¹ ......
typeof ÊÇJavaScriptµÄÔËËã·û
——·µ»ØÒ»¸öÓÃÀ´±íʾ±í´ïʽµÄÊý¾ÝÀàÐ͵Ä×Ö·û´®
typeof[(] expression [)] //typeofÓï·¨ÖеÄÔ²À¨ºÅÊÇ¿ÉÑ¡Ïî
typeof ÔËËã·û@import url(../html-vss/msdnie4a.css);
typeof
ÔËËã·û°ÑÀàÐÍÐÅÏ¢µ±×÷×Ö·û´®·µ»Ø¡£typeof
·µ»ØÖµÓÐÁ ......
function total(){
var i=0;
for(j=1;j<=20;j++)
{
var step="step"+j;
if(document.getElementById(step)){
if(document.getElementById(step).checked==true)
{
i=i+parseInt(document.getElementById(step).value);
}
}
}
document.getElementById("total").innerHTML = i;
}
function Resetvalue(){
......