[·Òë]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
Ïà¹ØÎĵµ£º
<script>
//дcookiesº¯Êý ×÷ÕߣºµÔÕñ¿
function
SetCookie(name,value)//Á½¸ö²ÎÊý£¬Ò»¸öÊÇcookieµÄÃû×Ó£¬Ò»¸öÊÇÖµ
{
var Days = 30;
//´Ë cookie ½«±»±£´æ 30 Ìì
var exp = new Date(); //new
Date("December 31, 9998");
  ......
JavaScriptʼþ´óÈ«
click() ¶ÔÏó.click() ʹ¶ÔÏó±»µã»÷¡£
closed ¶ÔÏó.closed ¶ÔÏó´°¿ÚÊÇ·ñÒѹرÕtrue/false
clearTimeout(¶ÔÏó) Çå³ýÒÑÉèÖõÄsetTimeout¶ÔÏó
clearInterval(¶ÔÏó) Çå³ýÒÑÉèÖõÄsetInterval¶ÔÏó
confirm("ÌáʾÐÅÏ¢") µ¯³öÈ·ÈÏ¿ò£¬È·¶¨·µ»ØtrueÈ¡Ïû·µ»Øfalse
cursor:Ñùʽ ¸ü¸ÄÊó±êÑùÊ ......
ClosureÖÐÎÄ·ÒëΪ±Õ°ü.×ÖÃæÉÏÀ´Àí½â¾ÍÊÇ"·â±ÕµÄ°ü".(ÕâÊÇÒ»¾ä·Ï»°)
±Õ°üÊÇʲô?
ÊéÃæ½âÊÍΪ:
Ëùν“±Õ°ü”£¬Ö¸µÄÊÇÒ»¸öÓµÓÐÐí¶à±äÁ¿ºÍ°ó¶¨ÁËÕâЩ±äÁ¿µÄ»·¾³µÄ±í´ïʽ£¨Í¨³£ÊÇÒ»¸öº¯Êý£©£¬Òò¶øÕâЩ±äÁ¿Ò²ÊǸñí´ïʽµÄÒ»²¿·Ö¡£
ÎÒÈÏΪ±Õ°ü¾ÍÊÇÄܹ»¶Á/дº¯ÊýÄÚ²¿µÄijЩ±äÁ¿µÄ×Óº¯Êý,²¢½«ÕâЩ±äÁ¿±£´æ ......
Òþ²Ø³ÉÔ±±äÁ¿
ÔÚº¯ÊýÌåÄÚ¶¨ÒåµÄ±äÁ¿Îª¾Ö²¿±äÁ¿£¬À뿪º¯Êý¾Í¹ÒµôÁË
ÔÚº¯ÊýÌåÄÚʹÓÃthis.³ÉÔ±±äÁ¿Ãû£¬ÔòΪwindow¶ÔÏó¼¶±äÁ¿£¬¼´È«¾Ö±äÁ¿
¹ÊÐèÒªÕâÑùÒþ²Ø³ÉÔ±±äÁ¿£¬ÏòÍâÖ»±©Â¶get¡¢setº¯Êý
function testClass(name){
var _firstname=name;
return {
getname : function() {
return _fir ......