File tree 1 file changed +49
-1
lines changed
1 file changed +49
-1
lines changed Original file line number Diff line number Diff line change 1
1
# CSS动画属性性能
2
2
3
3
* CSS动画属性会触发整个页面的重排relayout、重绘repaint、重组recomposite
4
- * Paint通常是其中最花费性能的,尽可能避免使用触发paint的CSS动画属性,这也是为什么我们推荐使用` webkit-transform: translateX(2em) ` 的方案代替使用` left: 3em ` ,因为` left ` 会额外触发layout与paint,而` webkit-transform ` 只触发整个页面composite
4
+ * Paint通常是其中最花费性能的,尽可能避免使用触发paint的CSS动画属性,这也是为什么我们推荐在CSS动画中使用` webkit-transform: translateX(3em) ` 的方案代替使用` left: 3em ` ,因为` left ` 会额外触发layout与paint,而` webkit-transform ` 只触发整个页面composite
5
+
6
+ ``` css
7
+ div {
8
+ -webkit-animation-duration : 5s ;
9
+ -webkit-animation-name : move ;
10
+ -webkit-animation-iteration-count : infinite ;
11
+ -webkit-animation-direction : alternate ;
12
+ width : 200px ;
13
+ height : 200px ;
14
+ margin : 100px ;
15
+ background-color : #808080 ;
16
+ position : absolute ;
17
+ }
18
+ ```
19
+
20
+ ``` css
21
+ @-webkit-keyframes move {
22
+ from {
23
+ left : 100px ;
24
+ }
25
+ to {
26
+ left : 200px ;
27
+ }
28
+ }
29
+ ```
30
+
31
+ 如下图使用` left ` 将持续触发页面重绘,表现为红色边框:
32
+
33
+ ![ move] ( https://f.cloud.github.com/assets/677114/1755561/a8fb9c94-6666-11e3-8788-ac5b5ef4ef24.gif )
34
+
35
+
36
+ ``` css
37
+ @-webkit-keyframes move {
38
+ from {
39
+ -webkit-transform : translateX (100px );
40
+ }
41
+ to {
42
+ -webkit-transform : translateX (200px );
43
+ }
44
+ }
45
+ ```
46
+
47
+ 如下图使用` -webkit-transform ` 页面只发生重组,表现为橙色边框:
48
+
49
+ ![ move2] ( https://f.cloud.github.com/assets/677114/1755562/aaef262e-6666-11e3-8e83-3e770f269af0.gif )
50
+
51
+ * CSS属性在CSS动画中行为表
5
52
6
53
![ CSS Property Animation on the Web] ( https://f.cloud.github.com/assets/677114/1752383/1f8c5e8e-661c-11e3-9725-306f7e5c73f5.png )
7
54
8
55
56
+
9
57
## 参考
10
58
* [ #perfmatters: 60fps layout and rendering] ( https://docs.google.com/presentation/d/1CH8ifryioHDLT1Oryyy8amusUmq2FytpCPCpk0G3E4o/edit#slide=id.p )
You can’t perform that action at this time.
0 commit comments