-
Notifications
You must be signed in to change notification settings - Fork 980
/
Copy pathanimation-direction.md
executable file
·106 lines (88 loc) · 2.62 KB
/
animation-direction.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
## scale 配合 transfrom-origin 精准控制动画方向
scale 配合 transfrom-origin 精准控制动画方向。
其中具体的一些细节,的可以看看我的这篇文章:
[妙用 scale 与 transfrom-origin,精准控制动画方向](https://github.com/chokcoco/iCSS/issues/63)
HTML:
```HTML
<div>Hover Me</div>
```
SCSS:
```scss
div {
position: absolute;
width: 200px;
height: 60px;
line-height: 60px;
font-size: 32px;
cursor: pointer;
color: #333;
text-align: center;
transition: color .5s;
margin: 20px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
div::before {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 200px;
transform: scaleX(0);
height: 2px;
background: deeppink;
z-index: -1;
transition: transform .5s;
transform-origin: 100% 0;
}
div:hover::before {
transform: scaleX(1);
transform-origin: 0 0;
}
```
效果如下:
<iframe height="300" style="width: 100%;" scrolling="no" title="transform-origin妙用" src="https://codepen.io/Chokcoco/embed/Bxyoyz?height=300&theme-id=default&default-tab=css,result" frameborder="no" allowtransparency="true" allowfullscreen="true">
See the Pen <a href='https://codepen.io/Chokcoco/pen/Bxyoyz'>transform-origin妙用</a> by Chokcoco
(<a href='https://codepen.io/Chokcoco'>@Chokcoco</a>) on <a href='https://codepen.io'>CodePen</a>.
</iframe>
------
当然,其实这只是其中一种方案。
不使用 `transform-orign` + `scale` 也是可以实现的,直接使用定位的方案如下:
HTML:
```HTML
<div>Hover Me</div>
```
SCSS:
```scss
div {
position: relative;
width: 200px;
height: 60px;
margin: auto;
line-height: 60px;
font-size: 32px;
cursor: pointer;
color: #333;
text-align: center;
transition: color .5s;
}
div::before {
content: "";
position: absolute;
right: 0;
bottom: 0;
width: 0;
height: 2px;
background: deeppink;
transition: all .5s;
}
div:hover::before {
left: 0;
width: 200px;
}
```
<iframe height="320" style="width: 100%;" scrolling="no" title="定位控制动画方向" src="https://codepen.io/Chokcoco/embed/rNVBZMa?height=320&theme-id=default&default-tab=css,result" frameborder="no" allowtransparency="true" allowfullscreen="true">
See the Pen <a href='https://codepen.io/Chokcoco/pen/rNVBZMa'>定位控制动画方向</a> by Chokcoco
(<a href='https://codepen.io/Chokcoco'>@Chokcoco</a>) on <a href='https://codepen.io'>CodePen</a>.
</iframe>