当前位置:网站首页>Redraw and reflow
Redraw and reflow
2022-07-03 04:13:00 【Chinese fir sauce_】
Rendering in the browser
- analysis HTML, formation DOM Trees , When encountering non blocking resources , For example, the image will continue to be parsed , When you meet css When you file , Will also continue to parse . When you meet js Blocking rendering of files , Will stop html Parsing .
- structure CSSOM Trees . The browser will css Rules are transformed into style maps that can be understood and used . Browser traversal CSS Each rule set in , according to CSS Selector creation has a parent 、 A node tree of child and sibling relationships .
- The third step is to DOM and CSSOM Combine into one Render Trees , Calculate the style or render tree from DOM The root of the tree begins to build , Traverse every visible node . Like and its child nodes and anything with
display:none
Nodes of styles , for examplescript {display:none;}
These labels will not show , That is, they will not appear in Render on the tree . havevisibility:hidden
The node will appear in Render on the tree , Because they take up space . Since we didn't give any instructions to override the user agent defaults , Therefore, in the above code example script Nodes will not be included in Render In the tree . - The fourth step is to run the layout on the rendering tree to calculate the geometry of each node .( backflow / rearrangement ). On this basis , Considering the size of the viewing area , The browser will determine the size of all the different boxes on the screen . Based on the size of the viewing area , Layout is usually from body Start , Arrange all with the model attributes of each element body The size of the descendant element , For replacement elements whose size is unknown ( Such as images ) Provide placeholder space .
- The last step is to draw the nodes on the screen .
backflow :
Based on the size of the viewing area , Layout is usually from body Start , Arrange all with the box model attribute of each element body The size of the descendant element , For replacement elements whose size is unknown ( Such as images ) Provide placeholder space .
All in all , Is to calculate them in the device viewport (viewport) The exact location and size of the inside ( That is, geometric attributes and positions ), The stage of calculation is reflux .
Repaint :
We can convert every node in the rendering tree into actual pixels on the screen , This stage is called the redraw node . That is to draw graphics on the screen , But if the background color changes , Then it will cause redrawing , But there will be no backflow .
Backflow must trigger a redraw , Redrawing doesn't necessarily trigger reflow .
Trigger reflow redrawing
- Add or remove visible DOM Elements
- The position of the element changes
- The size of the element changes ( Including margins 、 padding 、 The frame size 、 Height and width, etc )
- Content changes , Such as text changes or an image being replaced by another image of a different size .
- When the page starts to render ( It can't be avoided )
- The window size of the browser changes ( Because the backflow is based on the size of the viewport to calculate the location and size of the element )
Browser optimization mechanism
Each rearrangement results in additional computational overhead , Therefore, most browsers will optimize the rearrangement process through queue modification and batch execution . The browser queues up the changes , Until after a period of time or the operation reaches a certain threshold , Will clear the queue . however , When you get the operation of the layout information , A queue refresh is forced , Such as when you access the following properties or use the following methods :
- offsetTop、offsetLeft、offsetWidth、offsetHeight
- scroolTop、scroolLeft、scroolWidth、scroolHeight
- clientTop、clientLeft、clientWidth.clientHeight
- getComputedStyle()
- getBoundingClientRect
So when we modify the style , It is best to avoid using the properties listed above , They all refresh the render queue . If you want to use them , It is best to cache the values .
Ways to reduce reflow and redraw :
- The multiple DOM Operations are combined , Use csstext perhaps class
- Use cssText
const el = ducument.getElementById('test');
el.style.cssText += 'border-left: 1px;border-right: 2px; padding: 5px;';
- modify css Of class
const el = document.getElementById('test')
el.className += 'active';
- Make the node separate from the document flow ( That is, invisible nodes ), operation , Back to document flow .
- Use
display:none
- The layout event must be triggered
That is to say offset. If the same one is used many times offset, Then you can save its value before using . - For more complex animation, you can use absolute positioning to make it out of the document flow . For complex animation effects , Because it often causes reflow redrawing , therefore , We can use absolute positioning to separate it from the document flow , This causes frequent backflow of parent and subsequent elements .
边栏推荐
- MySQL timestampdiff interval
- Interface embedded in golang struct
- What is pytorch? Is pytorch a software?
- Reflection and planning of a sophomore majoring in electronic information engineering
- xrandr修改分辨率与刷新率
- Mila、渥太华大学 | 用SE(3)不变去噪距离匹配进行分子几何预训练
- MPLS setup experiment
- 基于Pytorch和RDKit的QSAR模型建立脚本
- Deep dive kotlin synergy (19): flow overview
- 2022 electrician (Advanced) examination papers and electrician (Advanced) examination skills
猜你喜欢
2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func main() { var a =
拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
2022-07-02:以下go语言代码输出什么?A:编译错误;B:Panic;C:NaN。 package main import “fmt“ func main() { var a =
CVPR 2022 | 大连理工提出自校准照明框架,用于现实场景的微光图像增强
在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
105. Detailed introduction of linkage effect realization of SAP ui5 master detail layout mode
The latest activation free version of Omni toolbox
"Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
Arduino application development - LCD display GIF dynamic diagram
『期末复习』16/32位微处理器(8086)基本寄存器
随机推荐
js/ts底层实现双击事件
300+篇文献!一文详解基于Transformer的多模态学习最新进展
因果AI,下一代可信AI的产业升级新范式?
[Blue Bridge Road - bug free code] pcf8591 - code analysis of AD conversion
Appium automated testing framework
How to download pytorch? Where can I download pytorch?
[set theory] set concept and relationship (set represents | number set | set relationship | contains | equality | set relationship property)
Practical operation of vim
中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》
[mathematical logic] predicate logic (judge whether the first-order predicate logic formula is true or false | explain | example | predicate logic formula type | forever true | forever false | satisfi
Wechat applet + Alibaba IOT platform + Hezhou air724ug build a serverless IOT system (III) -- wechat applet is directly connected to Alibaba IOT platform aliiot
深潜Kotlin协程(二十):构建 Flow
eth入门之简介
Appium自动化测试框架
[Blue Bridge Road -- bug free code] DS18B20 temperature reading code analysis
JMeter starts from zero (III) -- simple use of regular expressions
[Blue Bridge Road -- bug free code] interpretation of some codes of matrix keyboard
【毕业季·进击的技术er】职场人的自白
学会pytorch能干什么?
Database management tool, querious direct download