Author 王平安
E-mail pingan8787@qq.com
博 客 www.pingan8787.com
微 信 pingan8787
每日文章 https://0x9.me/KMrv3

参考文章
预览图

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>纯 CSS 创作一个“女神来了,快让路”的动画</title>
<style>
body,html{
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.container{
width: 8em;
height: 1em;
display: flex;
justify-content: space-between;
}
.container span{
width: 1em;
height: 1em;
--duration:3s;
}
.boys{
width: 6em;
display: flex;
justify-content: space-between;
}
.container span::before{
content: '';
position: absolute;
width: inherit;
height: inherit;
border-radius: 15%;
box-shadow: 0 0 .2em rgba(0, 0, 0, .3);
}
.girl:before{
background-color: hotpink;
}
.boys span::before{
background-color: dodgerblue;
animation: var(--duration) ease-in-out infinite;
}
.boys span:nth-child(1)::before{
filter: brightness(1);
animation-name: jump-down-1;
}
.boys span:nth-child(2)::before{
filter: brightness(1.15);
animation-name: jump-down-2;
}
.boys span:nth-child(3)::before{
filter: brightness(1.3);
animation-name: jump-down-3;
}
.boys span:nth-child(4)::before{
filter: brightness(1.45);
animation-name: jump-down-4;
}
.girl{
animation: slide var(--duration) ease-in-out infinite;
}
.boys span {
animation: var(--duration) ease-in-out infinite;
}
.boys span:nth-child(1){
animation-name: jump-off-1;
}
.boys span:nth-child(2){
animation-name: jump-off-2;
}
.boys span:nth-child(3){
animation-name: jump-off-3;
}
.boys span:nth-child(4){
animation-name: jump-off-4;
}

/* 女生方块 向右滑动 */
@keyframes slide{
from {
transform:translateX(0);
filter:brightness(1);
}
to{
transform: translateX(calc(8em - (1em * 1.25)));
filter: brightness(1.45);
}
}
/* 第1个男生方块跳动 */
@keyframes jump-off-1 {
0%, 15%{
transform: rotate(0deg);
}
35%, 100%{
transform-origin: -50% center;
transform: rotate(-180deg);
}
}
/* 第2个男生方块跳动 */
@keyframes jump-off-2 {
0%, 30%{
transform: rotate(0deg);
}
50%, 100%{
transform-origin: -50% center;
transform: rotate(-180deg);
}
}
/* 第3个男生方块跳动 */
@keyframes jump-off-3 {
0%, 45%{
transform: rotate(0deg);
}
65%, 100%{
transform-origin: -50% center;
transform: rotate(-180deg);
}
}
/* 第4个男生方块跳动 */
@keyframes jump-off-4 {
0%, 60%{
transform: rotate(0deg);
}
80%, 100%{
transform-origin: -50% center;
transform: rotate(-180deg);
}
}

/* 动画的过程是从正常到压扁、然后抻长、再压扁、最后恢复正常 */
@keyframes jump-down-1 {
5%{
transform: scale(1,1);
}
15%{
transform-origin: center bottom;
transform: scale(1.3, 0.7);
}
20%, 25%{
transform-origin: center bottom;
transform: scale(0.8, 1.4);
}
40%{
transform-origin: center bottom;
transform: scale(1.3, 0.7);
}
55%, 100%{
transform: scale(1, 1);
}
}
@keyframes jump-down-2 {
20%{
transform: scale(1,1);
}
30%{
transform-origin: center bottom;
transform: scale(1.3, 0.7);
}
35%, 40%{
transform-origin: center bottom;
transform: scale(0.8, 1.4);
}
55%{
transform-origin: center bottom;
transform: scale(1.3, 0.7);
}
70%, 100%{
transform: scale(1, 1);
}
}
@keyframes jump-down-3 {
35%{
transform: scale(1,1);
}
45%{
transform-origin: center bottom;
transform: scale(1.3, 0.7);
}
50%, 55%{
transform-origin: center bottom;
transform: scale(0.8, 1.4);
}
70%{
transform-origin: center bottom;
transform: scale(1.3, 0.7);
}
85%, 100%{
transform: scale(1, 1);
}
}
@keyframes jump-down-4 {
50%{
transform: scale(1,1);
}
60%{
transform-origin: center bottom;
transform: scale(1.3, 0.7);
}
65%, 70%{
transform-origin: center bottom;
transform: scale(0.8, 1.4);
}
85%{
transform-origin: center bottom;
transform: scale(1.3, 0.7);
}
100%, 100%{
transform: scale(1, 1);
}
}
</style>
</head>
<body>
<!-- 原文 https://segmentfault.com/a/1190000016287188 -->
<div class="container">
<span class="girl"></span>
<div class="boys">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
</body>
</html>