html – 什么是DOM回流?

前端之家收集整理的这篇文章主要介绍了html – 什么是DOM回流?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在阅读两个css属性之间的区别显示:无和可见性:隐藏并遇到DOM回流术语。

声明是

display: none causes DOM reflow where is visibility: hidden doesn’t.

所以我的问题是:

什么是DOM回流及其工作原理?

解决方法

A reflow computes the layout of the page. A reflow on an element recomputes the dimensions and position of the element,and it also triggers further reflows on that element’s children,ancestors and elements that appear after it in the DOM. Then it calls a final repaint. Reflowing is very expensive,but unfortunately it can be triggered easily.

Reflow occurs when you:

  • insert,remove or update an element in the DOM
  • modify content on the page,e.g. the text in an input Box
  • move a DOM element
  • animate a DOM element
  • take measurements of an element such as offsetHeight or getComputedStyle
  • change a CSS style
  • change the className of an element
  • add or remove a stylesheet
  • resize the window
  • scroll

欲了解更多信息,请参阅:Repaints and Reflows: Manipulating the DOM responsibly

猜你在找的HTML相关文章