浏览器的渲染原理
TL;DR
- The DOM and CSSOM trees are combined to form the render tree.
- 构建渲染 DOM 和 CSSOM 树
- Render tree contains only the nodes required to render the page.
- 渲染树仅包含渲染页面所需要的节点
- Layout computes the exact position and size of each object.
- 布局需要计算每个节点的位置和大小
- The last step is paint, which takes in the final render tree and renders the pixels to the screen.
- 最后一步是绘制,采用最终的渲染树,并将最终的渲染结果渲染到屏幕上面
具体步骤
- Process HTML markup and build the DOM tree.
- 解析
HTML并构建DOM树
- 解析
- Process CSS markup and build the CSSOM tree.
- 解析
CSS并构建CSSOM树
- 解析
- Combine the DOM and CSSOM into a render tree.
- 解析
DOM树和CSSOM树并构建渲染树
- 解析
- Run layout on the render tree to compute geometry of each node.
- 解析渲染树并且计算出每个节点的大小和形状
- Paint the individual nodes to the screen.
- 上色,并绘制到屏幕上
动画的两种做法
transition
transition CSS 属性是 transition-property,transition-duration,transition-timing-function 和 transition-delay 的一个简写属性。
| /* Apply to 1 property */ | |
| /* property name | duration */ | |
| transition: margin-right 4s; | |
| /* property name | duration | delay */ | |
| transition: margin-right 4s 1s; | |
| /* property name | duration | easing function */ | |
| transition: margin-right 4s ease-in-out; | |
| /* property name | duration | easing function | delay */ | |
| transition: margin-right 4s ease-in-out 1s; | |
| /* Apply to 2 properties */ | |
| transition: margin-right 4s, color 1s; | |
| /* Apply to all changed properties */ | |
| transition: all 0.5s ease-out; | |
| /* Global values */ | |
| transition: inherit; | |
| transition: initial; | |
| transition: revert; | |
| transition: revert-layer; | |
| transition: unset; |
transform
animation: 时长 | 过渡方式 | 延迟 | 次数 | 方向 |填充模式 | 是否暂停 | 动画名;
| /* @keyframes duration | timing-function | delay | | |
| iteration-count | direction | fill-mode | play-state | name */ | |
| animation: 3s ease-in 1s 2 reverse both paused slidein; | |
| /* @keyframes duration | timing-function | delay | name */ | |
| animation: 3s linear 1s slidein; | |
| /* @keyframes duration | name */ | |
| animation: 3s slidein; |
完整示例:即加 @keyframes
| #demo.start{ | |
| animation: 1.5s ease 1s infinite alternate forwards xxx ; | |
| } | |
| @keyframes xxx { | |
| 0% { | |
| transform: none; | |
| } | |
| 66.66%{ | |
| transform: translateX(200px); | |
| } | |
| 100%{ | |
| transform: translateX(200px) translateY(100px); | |
| } | |
| } |
其他List
- 感觉不大熟悉的是 float 里面那个 负margin
- 以及 清除浮动 感觉有点陌生,这几节的笔记要经常翻一下
- 多做一些小项目吧,把学到的都复习一下 不大容易忘了就
资料来源:饥人谷。任何组织或个人未经许可,禁止转载
评论






