吃豆人加载动画

本文最后更新于:2023年11月5日 晚上

效果

纯HTML

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
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
.loading {
display: flex;
align-items: center;
justify-content: space-around;
width: 100px;
height: 30px;
perspective: 200px;
transform-style: preserve-3d;
}

.loading .player {
position: absolute;
left: 0;
top: 0;
height: 30px;
width: 30px;
animation: playerMove linear 4s infinite;
}

.loading .player .top-mouth,
.loading .player .bottom-mouth {
position: absolute;
width: 0;
height: 0;
border: 15px solid #fbbc05;
transform: rotate(45deg);
border-radius: 50%;
}

.loading .player .top-mouth {
border-bottom-color: transparent;
border-right-color: transparent;
transform: rotate(30deg);
animation: topBite 0.2s ease-in-out infinite alternate;
}

.loading .player .top-mouth::after {
content: '';
position: absolute;
margin-top: -11px;
margin-left: -3px;
width: 5px;
height: 5px;
border-radius: 50%;
background-color: #000;
}

.loading .player .bottom-mouth {
border-top-color: transparent;
border-left-color: transparent;
transform: rotate(60deg);
animation: bottomBite 0.2s ease-in-out infinite alternate;
}

.loading span.bean:nth-of-type(1) {
width: 13px;
height: 13px;
border-radius: 50%;
background-color: #1875e5;
animation: beanOut1 4s linear infinite;
}

.loading span.bean:nth-of-type(2) {
width: 13px;
height: 13px;
border-radius: 50%;
background-color: #fbbc05;
animation: beanOut2 4s linear infinite;
}

.loading span.bean:nth-of-type(3) {
width: 13px;
height: 13px;
border-radius: 50%;
background-color: #499255;
animation: beanOut3 4s linear infinite;
}

@keyframes topBite {
0% {
transform: rotate(45deg);
}
100% {
transform: rotate(20deg);
}
}

@keyframes bottomBite {
0% {
transform: rotate(45deg);
}
100% {
transform: rotate(80deg);
}
}

@keyframes playerMove {
0% {
transform: translateX(0) translateZ(10px);
}
30% {
transform: translateX(70px) translateZ(10px);
}
50% {
transform: translateX(70px) translateZ(10px) rotateY(180deg);
}
80% {
transform: translateX(0) translateZ(10px) rotateY(180deg);
}
100% {
transform: translateX(0) translateZ(10px) rotateY(360deg);
}
}

/**
0% - 15% 吃豆人从起始点向左到中点的过程
15% - 30% 吃豆人从中点向左到终点的过程
30% - 50% 吃豆人在终点回头的过程
50% - 65% 吃豆人从终点向右到中点的过程
65% - 80% 吃豆人从中点到起始点的过程
80% - 100% 吃豆人在起始点回头的过程
*/
@keyframes beanOut1 {
0% {
opacity: 0;
}
15% {
opacity: 0;
}
30% {
opacity: 1;
}
74% {
opacity: 1;
}
77% {
opacity: 0;
}
80% {
opacity: 0;
}
100% {
opacity: 0;
}
}

@keyframes beanOut2 {
0% {
opacity: 1;
}
9% {
opacity: 1;
}
12% {
opacity: 0;
}
15% {
opacity: 0;
}
30% {
opacity: 0;
}
50% {
opacity: 1;
}
59% {
opacity: 1;
}
62% {
opacity: 0;
}
65% {
opacity: 0;
}
80% {
opacity: 0;
}
100% {
opacity: 1;
}
}

@keyframes beanOut3 {
0% {
opacity: 1;
}
15% {
opacity: 1;
}
24% {
opacity: 1;
}
27% {
opacity: 0;
}
30% {
opacity: 0;
}
50% {
opacity: 0;
}
65% {
opacity: 0;
}
80% {
opacity: 1;
}
100% {
opacity: 1;
}
}
</style>
</head>

<body>
<div id="app">
<div class="loading-container">
<div class="loading">
<div class="player">
<div class="top-mouth"></div>
<div class="bottom-mouth"></div>
</div>
<span class="bean"></span>
<span class="bean"></span>
<span class="bean"></span>
</div>
</div>
</div>

Vue 组件

FLoading.vue

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
<template>
<div class="loading">
<div class="player">
<div class="top-mouth"></div>
<div class="bottom-mouth"></div>
</div>
<span class="bean"></span>
<span class="bean"></span>
<span class="bean"></span>
</div>
</template>

<style scoped lang="scss">
.loading {
display: flex;
align-items: center;
justify-content: space-around;
width: 100px;
height: 30px;
perspective: 200px;
transform-style: preserve-3d;

.player {
position: absolute;
left: 0;
top: 0;
height: 30px;
width: 30px;
animation: playerMove linear 4s infinite;

// 上下鄂
.top-mouth, .bottom-mouth {
position: absolute;
width: 0;
height: 0;
border: 15px solid #fbbc05;
transform: rotate(45deg);
border-radius: 50%;
}

.top-mouth {
border-bottom-color: transparent;
border-right-color: transparent;
transform: rotate(30deg);
animation:
topBite .2s ease-in-out infinite alternate;

&::after {
content: '';
position: absolute;
margin-top: -11px;
margin-left: -3px;
width: 5px;
height: 5px;
border-radius: 50%;
background-color: #000;
}
}

.bottom-mouth {
border-top-color: transparent;
border-left-color: transparent;
transform: rotate(60deg);
animation:
bottomBite .2s ease-in-out infinite alternate;
}
}

span.bean:nth-of-type(1) {
width: 13px;
height: 13px;
border-radius: 50%;
background-color: #1875e5;
animation: beanOut1 4s linear infinite;
}

span.bean:nth-of-type(2) {
width: 13px;
height: 13px;
border-radius: 50%;
background-color: #fbbc05;
animation: beanOut2 4s linear infinite;
}
span.bean:nth-of-type(3) {
width: 13px;
height: 13px;
border-radius: 50%;
background-color: #499255;
animation: beanOut3 4s linear infinite;
}
}

@keyframes topBite {
0% {
transform: rotate(45deg);
}
100% {
transform: rotate(20deg);
}
}

@keyframes bottomBite {
0% {
transform: rotate(45deg);
}
100% {
transform: rotate(80deg);
}
}

@keyframes playerMove {
0% {
// 总时间 .3 向右移动
transform: translateX(0) translateZ(10px);
}

30% {
// .2 转身
transform: translateX(70px) translateZ(10px);
}

50% {
// .3 向左移动
transform: translateX(70px) translateZ(10px) rotateY(180deg);
}

80% {
// .2 转身
transform: translateX(0) translateZ(10px) rotateY(180deg)
}

100% {
transform: translateX(0) translateZ(10px) rotateY(360deg);
}
}

/**
0% - 15% 吃豆人从起始点向左到中点的过程
15% - 30% 吃豆人从中点向左到终点的过程
30% - 50% 吃豆人在终点回头的过程
50% - 65% 吃豆人从终点向右到中点的过程
65% - 80% 吃豆人从中点到起始点的过程
80% - 100% 吃豆人在起始点回头的过程
*/
@keyframes beanOut1 {
0% {
opacity: 0;
}

15% {
opacity: 0;
}

30% {
opacity: 1;
}

74% {
opacity: 1;
}

77% {
opacity: 0;
}

80% {
opacity: 0;
}

100% {
opacity: 0;
}
}
@keyframes beanOut2 {
0% {
opacity: 1;
}

9% {
opacity: 1;
}

12% {
opacity: 0;
}

15% {
opacity: 0;
}

30% {
opacity: 0;
}

50% {
opacity: 1;
}

59% {
opacity: 1;
}

62% {
opacity: 0;
}

65% {
opacity: 0;
}

80% {
opacity: 0;
}

100% {
opacity: 1;
}
}
@keyframes beanOut3 {
0% {
opacity: 1;
}

15% {
opacity: 1;
}

24% {
opacity: 1;
}

27% {
opacity: 0;
}

30% {
opacity: 0;
}

50% {
opacity: 0;
}

65% {
opacity: 0;
}

80% {
opacity: 1;
}

100% {
opacity: 1;
}
}
</style>

使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<script>
import { defineComponent } from "vue";
import FLoading from "@/FLoading.vue";

export default defineComponent({
components: { FLoading }
})
</script>

<template>
<div class="loading-container">
<FLoading />
</div>
</template>
<style scoped lang="scss">
.loading-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
</style>

吃豆人加载动画
https://xin-fas.github.io/2023/09/05/吃豆人加载动画/
作者
Xin-FAS
发布于
2023年9月5日
更新于
2023年11月5日
许可协议