《前端如何实现Aniplex动画效果》

html 部分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<div class="box">
<div class="chars">A</div>
<div class="chars">N</div>
<div class="chars">I</div>
<div class="chars">P</div>
<div class="chars">L</div>
<div class="chars">E</div>
<div class="chars">X</div>
<div class="ll a"></div>
<div class="ll n"></div>
<div class="ll i"></div>
<div class="ll p"></div>
<div class="ll l"></div>
<div class="ll e"></div>
<div class="ll x"></div>
<div class="pcov"></div>
</div>

css 部分

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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
* {
/* 初始化 取消页面内外边距 */
margin: 0;
padding: 0;
}
.box {
background-color: #000;
/* 100%窗口宽度和高度 */
width: 100vw;
height: 100vh;
/* 弹性布局 水平、垂直居中 */
display: flex;
justify-content: center;
align-items: center;
/* 横向排列 */
flex-direction: row;
/* 将平面图形转换为具有透视的3D图形 */
perspective: 300;
-webkit-perspective: 300;
overflow: hidden;
}
/* 动画字符所在的块 */
.chars {
color: #fff;
/* 相对定位 */
position: relative;
width: 60px;
height: 60px;
text-align: center;
line-height: 60px;
font-size: 54px;
font-weight: 900;
/* 斜体 */
font-style: italic;
margin: 0 10px;
opacity: 0;
}
/* 字符外的方框 */
.ll {
/* 绝对定位 */
position: absolute;
margin-left: -480px;
width: 60px;
height: 60px;
border-radius: 3px;
opacity: 0;
}
.x {
border: 4px solid #f5b5fc;
/* 执行动画:动画名称 时长 线性的 停留在最后一帧 */
animation: xmove 2s linear forwards;
}
.e {
border: 4px solid #96f7d2;
animation: emove 2s linear forwards;
/* 设置动画延迟 */
animation-delay: 0.1s;
}
.l {
border: 4px solid #f0f696;
animation: lmove 2s linear forwards;
animation-delay: 0.2s;
}
.p {
border: 4px solid #fcb1b1;
animation: pmove 2s linear forwards;
animation-delay: 0.3s;
}
.i {
border: 4px solid #f0f696;
animation: imove 2s linear forwards;
animation-delay: 0.4s;
}
.n {
border: 4px solid #96f7d2;
animation: nmove 2s linear forwards;
animation-delay: 0.5s;
}
.a {
border: 4px solid #f5b5fc;
animation: amove 2s linear forwards;
animation-delay: 0.6s;
}
/* 正中间的一条线 */
.pcov {
position: absolute;
width: 4px;
height: 60px;
background-color: #fcb1b1;
opacity: 0;
animation: showp forwards;
animation-delay: 2.3s;
}

/* 定义动画 */
/* 显示正中间的那条线 */
@keyframes showp {
from {
opacity: 0;
}
to {
transform: scale(1, 2);
opacity: 1;
}
}
/* A字符外方框的动画 */
@keyframes amove {
0% {
opacity: 1;
transform: rotateY(0deg);
}
50% {
transform: rotateY(180deg);
}
100% {
opacity: 1;
transform: rotateY(360deg);
}
}
/* N字符外方框的动画 */
@keyframes nmove {
30% {
opacity: 1;
transform: translate(30px) rotateY(135deg) scale(1.1, 1.1);
}
60% {
transform: translate(50px) rotateY(45deg) scale(1.1, 1.1);
}
85% {
transform: translate(80px) rotateY(103deg) scale(1.2, 1.2);
}
100% {
opacity: 1;
z-index: -99;
transform: translate(80px) rotateY(77deg) scale(1.2, 1.2);
}
}
/* I字符外方框的动画 */
@keyframes imove {
30% {
opacity: 1;
transform: translate(60px) rotateY(135deg) scale(1.2, 1.2);
}
60% {
transform: translate(120px) rotateY(45deg) scale(1.3, 1.3);
}
85% {
transform: translate(160px) rotateY(103deg) scale(1.3, 1.3);
}
100% {
opacity: 1;
transform: translate(164px) rotateY(77deg) scale(1.3, 1.3);
}
}
/* P字符外方框的动画 */
@keyframes pmove {
30% {
opacity: 1;
transform: translate(60px) rotateY(135deg) scale(1.2, 1.2);
}
60% {
transform: translate(120px) rotateY(45deg) scale(1.4, 1.4);
}
85% {
transform: translate(240px) rotateY(135deg) scale(1.6, 1.6);
}
100% {
opacity: 1;
transform: translate(240px) rotateY(90deg) scale(1.6, 1.6);
}
}
/* L字符外方框的动画 */
@keyframes lmove {
33% {
opacity: 1;
transform: translate(80px) rotateY(135deg) scale(1.2, 1.2);
}
66% {
transform: translate(240px) rotateY(45deg) scale(1.6, 1.6);
}
95% {
transform: translate(320px) rotateY(100deg) scale(1.4, 1.4);
}
100% {
opacity: 1;
transform: translate(320px) rotateY(103deg) scale(1.3, 1.3);
}
}
/* E字符外方框的动画 */
@keyframes emove {
33% {
opacity: 1;
transform: translate(80px) rotateY(135deg) scale(1.2, 1.2);
}
66% {
transform: translate(240px) rotateY(45deg) scale(1.6, 1.6);
}
95% {
transform: translate(390px) rotateY(135deg) scale(1.2, 1.2);
}
100% {
opacity: 1;
transform: translate(402px) rotateY(103deg) scale(1.2, 1.2);
}
}
/* X字符外方框的动画 */
@keyframes xmove {
25% {
opacity: 1;
transform: translate(100px) rotateY(135deg) scale(1.2, 1.2);
}
50% {
transform: translate(260px) rotateY(45deg) scale(1.6, 1.6);
}
85% {
transform: translate(400px) rotateY(135deg) scale(1.2, 1.2);
}
100% {
opacity: 1;
transform: translate(484px) rotateY(0deg) scale(1, 1);
}
}
/* 前两个字符的动画 */
@keyframes show12 {
0% {
opacity: 1;
transform: rotateY(0deg);
}
100% {
opacity: 1;
transform: rotateY(360deg);
}
}
/* 第3个及之后的字符的动画 */
@keyframes show3 {
0% {
opacity: 1;
transform: rotateY(90deg);
}
100% {
opacity: 1;
transform: rotateY(360deg);
}
}

/* 为每个字符添加动画 */
.box div:nth-child(1) {
animation: show12 1.2s linear forwards;
animation-iteration-count: 2;
animation-delay: 0.2s;
}
.box div:nth-child(2) {
animation: show12 1.2s linear forwards;
animation-iteration-count: 2;
animation-delay: 0.4s;
}
.box div:nth-child(3) {
animation: show3 1s linear 1 forwards;
animation-delay: 0.7s;
}
.box div:nth-child(4) {
animation: show3 1s linear 1 forwards;
animation-delay: 0.9s;
}
.box div:nth-child(5) {
animation: show3 1s linear 1 forwards;
animation-delay: 1.1s;
}
.box div:nth-child(6) {
animation: show3 1.2s linear 1 forwards;
animation-delay: 1.3s;
}
.box div:nth-child(7) {
animation: show3 1.2s linear 1 forwards;
animation-delay: 1.6s;
}