html - 什么是 DOM 回流?

标签 html css dom visibility reflow

我在阅读两个 CSS 属性 display:nonevisibility:hidden 之间的区别时遇到了 DOM reflow 术语。

声明是

display: none causes a DOM reflow whereas visibility: hidden does not.

所以我的问题是:

什么是 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 - 什么是 DOM 回流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27637184/

相关文章:

javascript - 如何搜索 DOM 元素的所有 <input> 后代并禁用它们

javascript - Chrome 在隐藏和显示父 DIV 容器时重新加载嵌入式 SVG 对象

html - 选择div css下的内容

javascript - 单击后将div重置为原始位置

css - 如何用文字获得玻璃 splinter 效果

javascript - 如何获得总用户中的页面访问者百分比

javascript - "onscroll"在重绘之后或之前触发?

html - 在导航栏中使用图标的缩放问题

html - 列表社交媒体链接的 ARIA 作用

html - Bootstrap 导航栏以特定宽度创建两行