DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS進階教程
網頁效能入門:透徹理解 reflow(重排)的概念
編輯:CSS進階教程     

如果你對 reflow 這個概念還不太清楚,建議先閱讀以下延伸資料:

  • 《Notes on HTML Reflow》
  • 《What is a reflow?》
  • 《Gecko:Reflow Refactoring》
  • 《reflow》
  • 《形象化的 reflow》
  • 《樣式的執行效率-reflow》

Yahoo! 效能工程師 Nicole Sullivan 在文章《Reflows & Repaints: CSS Performance making your JavaScript slow?》中,歸納了導致 reflow 發生的一些因素:

  1. 調整視窗大小(Resizing the window)
  2. 改變字型(Changing the font)
  3. 增加或移除樣式表(Adding or removing a stylesheet)
  4. 內容變化,例如使用者在 input 框中輸入文字(Content changes)
  5. 啟用 CSS 偽類,如 :hover(在 IE 中為啟用兄弟節點的偽類)
  6. 操作 class 屬性(Manipulating the class attribute)
  7. 腳本操作 DOM(A script manipulating the DOM)
  8. 計算 offsetWidth 和 offsetHeight 屬性
  9. 設定 style 屬性的值(Setting a property of the style attribute)

reflow 會帶來開銷、影響頁面效能,那該如何合理優化呢?Nicole Sullivan 也提供了部分建議:

  1. 想設定元素樣式時,透過改變元素的 class 名(盡量放在 DOM 樹的最內層)。
  2. 避免一次設定多項內聯樣式。
  3. 為元素套用動畫時,使用 position 的 fixed 或 absolute 值。
  4. 在平滑度與速度之間權衡取捨。
  5. 避免使用 table 排版。
  6. 避免在 CSS 中使用 JavaScript 表達式(僅 IE 瀏覽器)。

詳細閱讀:《Reflows & Repaints: CSS Performance making your JavaScript slow?》

原文:https://www.planabc.net/2009/04/13/reflow/

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved