CSS轻松实现流星特效


CSS轻松实现流星特效

2025年了,让我们来实现一款炫酷的流星特效,为新的一年许下真诚的祝福~

特效如下

源码

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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>流星特效</title>
<style>
html {
background-color: #000;
}
.container {
position: relative;
width: 500px;
height: 500px;
margin: 200px auto;
}
.meteor {
position: absolute;
width: 4px;
height: 4px;
border-radius: 50%;
pointer-events: none;
opacity: 0;
}
/* 流行尾巴 */
.meteor .tail {
position: absolute;
width: 100px;
height: 2px;
right: 0;
top: 50%;
transform: translateY(-50%);
background: linear-gradient(to left, currentColor, transparent);
}
.meteor:nth-child(1) { color: #ff9a9e; top: 10%; left: 200px; animation: meteor 3s linear infinite; }
.meteor:nth-child(2) { color: #4facfe; top: 20%; left: 200px; animation: meteor 3s linear infinite 1s; }
.meteor:nth-child(3) { color: #81FBB8; top: 30%; left: 200px; animation: meteor 3s linear infinite 0.5s; }
.meteor:nth-child(4) { color: #ffd34f; top: 40%; left: 200px; animation: meteor 3s linear infinite 1.5s; }
.meteor:nth-child(5) { color: #c471f5; top: 50%; left: 200px; animation: meteor 3s linear infinite 0.8s; }
.meteor:nth-child(6) { color: #43e97b; top: 60%; left: 200px; animation: meteor 3s linear infinite 2s; }
.meteor:nth-child(7) { color: #fa71cd; top: 70%; left: 200px; animation: meteor 3s linear infinite 1.2s; }
.meteor:nth-child(8) { color: #a8c0ff; top: 80%; left: 200px; animation: meteor 3s linear infinite 0.3s; }

@keyframes meteor {
0% {
opacity: 0;
transform: translate(0, 0) rotate(45deg);
}
10% {
opacity: 1;
}
20% {
transform: translate(30px, 30px) rotate(45deg);
}
40% {
transform: translate(60px, 60px) rotate(45deg);
}
60% {
transform: translate(90px, 90px) rotate(45deg);
opacity: 1;
}
100% {
transform: translate(120px, 120px) rotate(45deg);
opacity: 0;
}
}
</style>
</head>
<body>
<div class="container">
<div class="meteor"><div class="tail"></div></div>
<div class="meteor"><div class="tail"></div></div>
<div class="meteor"><div class="tail"></div></div>
<div class="meteor"><div class="tail"></div></div>
<div class="meteor"><div class="tail"></div></div>
<div class="meteor"><div class="tail"></div></div>
<div class="meteor"><div class="tail"></div></div>
<div class="meteor"><div class="tail"></div></div>
</div>
</body>
</html>

我的微信公众号: 梨的前端小屋


文章作者: 梨啊梨
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 梨啊梨 !
  目录