CSS3实现声音跳动效果

声音跳动效果

HTML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<div class="p-waves-group">
<div class="p-waves p-waves__left">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="p-waves p-waves__right">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</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
.p-waves-group {
z-index: 1;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;

.p-waves {
position: absolute;
top: 9px;
height: 20px;
display: flex;
align-items: center;
justify-content: flex-start;

@keyframes mywaves {
0% {
height: 8px;
bottom: 0
}
25% {
height: 14px;
bottom: 0
}
50% {
height: 20px;
bottom: 0
}
75% {
height: 14px;
bottom: 0
}
100% {
height: 8px;
bottom: 0
}
}

span {
display: inline-flex;
width: 3px;
height: 8px;
border-radius: 1.5px;
background: hsla(0, 0%, 100%, .3);
-webkit-animation: mywaves 1.2s ease-in-out infinite;
animation: mywaves 1.2s ease-in-out infinite;
margin-left: 4px;
-webkit-box-sizing: content-box;
box-sizing: content-box;
background-clip: content-box;
}

span:first-child, span:nth-child(5) {
-webkit-animation-delay: 0.1s;
animation-delay: 0.1s;
}

span:nth-child(1), span:nth-child(4) {
-webkit-animation-delay: .2s;
animation-delay: .2s;
}

span:nth-child(2) {
-webkit-animation-delay: .6s;
animation-delay: .6s;
}

span:nth-child(3) {
-webkit-animation-delay: .9s;
animation-delay: .9s;
}
}

.p-waves__left {
left: 8px;
}

.p-waves__right {
right: 8px;
}
}