Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

介绍下重绘和回流 #62

Open
GGXXMM opened this issue Nov 16, 2020 · 0 comments
Open

介绍下重绘和回流 #62

GGXXMM opened this issue Nov 16, 2020 · 0 comments
Labels

Comments

@GGXXMM
Copy link
Owner

GGXXMM commented Nov 16, 2020

重绘 Repaint

由于页面元素的样式改变而不影响布局时(例如:visibilitycolorbackground-color等),浏览器会将新样式赋给元素并重新绘制它,这个过程称为重绘。

重排(回流) Reflow

Render Tree中的部分或全部的元素节点的尺寸、结构或几何属性发生改变时,浏览器重新渲染部分或全部的文档的过程叫回流。

会导致重排的操作:

  • 页面首次渲染
  • 浏览器窗口大小发生变化
  • 元素尺寸/位置发生变化
  • 元素内容变化(文字数量、图片大小等)
  • 元素字体大小变化
  • 添加/删除可见的DOM元素
  • 激活CSS伪类(如:hover)
  • 查询某些属性/方法

会导致重排的属性和方法:

  • clientWidth、clientHeight、clientTop、clientLeft
  • offsetWidth、offsetHeight、offsetTop、offsetLeft
  • scrollWidth、scrollHeight、scrollTop、scrollLeft
  • scrollIntoView()、scrollIntoViewIfNeeded()
  • getComputedStyle()
  • getBoundingClientRect()
  • scrollTo()

注意:回流必定会引起重绘,重绘不一定会引发回流。

@GGXXMM GGXXMM added the css label Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant