主要CSS

  • animation
  • transform: scale()
  • opacity
  • nth-child()

效果展示

动画

代码

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
<div>
<style>
.ripple {
width: 200px;
height: 200px;
position: absolute;
top: calc(50% - 100px);
left: calc(50% - 100px);
border-radius: 50%;
background-color: blueviolet;
}
/* 根据需求自定义 */
.content{
position: absolute;
z-index: 99;
/* 与.ripple的top和left相同 */
top: calc(50% - 100px);
left: calc(50% - 100px);

width: 200px;
height: 200px;
border-radius: 50%;
background-color: rgb(42, 42, 180);

font-size: 20px;
font-weight: bold;
color: #FFF;
text-align: center;
line-height: 200px;
}
.ripple:nth-child(2){
animation: wave 1s linear infinite;
}

.ripple:nth-child(3){
animation: wave 2s linear infinite;
}

.ripple:nth-child(4){
animation: wave 3s linear infinite;
}
.ripple:nth-child(5){
animation: wave 4s linear infinite;
}

@keyframes wave {
from {
opacity: 1;
transform: scale(1);
}

to {
opacity: 0;
transform: scale(1.5);
}
}
</style>
<div class="box">
<div class="content">内容</div>
<div class="ripple"></div>
<div class="ripple"></div>
<div class="ripple"></div>
<div class="ripple"></div>
<div class="ripple"></div>
</div>
</div>

实现的逻辑就是通过animation动画重复将这些元素放大1.5倍,同时将元素变为完全透明,从而达到波纹扩散的效果