两款简洁的 loading 动画

HTML

1
2
3
4
5
6
7
8
<!-- 动画1 -->
<div class="donut"></div>
<!-- 动画2 -->
<div class="bouncing-loader">
<div></div>
<div></div>
<div></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
@keyframes donut-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

.donut {
margin: 0 auto;
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: #7983ff;
border-radius: 50%;
width: 30px;
height: 30px;
animation: donut-spin 1.2s linear infinite;
}

@keyframes bouncing-loader {
from {
opacity: 1;
transform: translateY(0);
}
to {
opacity: 0.1;
transform: translateY(-1rem);
}
}

.bouncing-loader {
display: flex;
justify-content: center;
}

.bouncing-loader > div {
width: 1rem;
height: 1rem;
margin: 3rem 0.2rem;
background: #000;
border-radius: 50%;
animation: bouncing-loader 0.6s infinite alternate;
}

.bouncing-loader > div:nth-child(2) {
animation-delay: 0.2s;
}

.bouncing-loader > div:nth-child(3) {
animation-delay: 0.4s;
}

效果

录屏速度有点快,实际上动画速度是正常的(移动端可能不会动)