<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>纯CSS3流星雨划过动画特效</title>
<style>
body {
margin: 0;
padding: 0;
height: 100vh;
background: #0a0e17;
overflow: hidden;
font-family: Arial, sans-serif;
}
.night-sky {
position: relative;
width: 100%;
height: 100%;
}
.star {
position: absolute;
background: white;
border-radius: 50%;
animation: twinkle 3s infinite alternate;
}
/* 创建随机星星 */
.star:nth-child(1) {
width: 2px;
height: 2px;
top: 15%;
left: 20%;
animation-delay: 0.5s;
}
.star:nth-child(2) {
width: 3px;
height: 3px;
top: 25%;
left: 40%;
animation-delay: 1s;
}
.star:nth-child(3) {
width: 1px;
height: 1px;
top: 10%;
left: 60%;
animation-delay: 1.5s;
}
.star:nth-child(4) {
width: 2px;
height: 2px;
top: 30%;
left: 80%;
animation-delay: 0.8s;
}
.star:nth-child(5) {
width: 3px;
height: 3px;
top: 50%;
left: 30%;
animation-delay: 0.3s;
}
.star:nth-child(6) {
width: 1px;
height: 1px;
top: 70%;
left: 50%;
animation-delay: 2s;
}
.star:nth-child(7) {
width: 2px;
height: 2px;
top: 65%;
left: 70%;
animation-delay: 1.2s;
}
.meteor {
position: absolute;
width: 150px;
height: 1px;
background: linear-gradient(to right, rgba(255,255,255,0), #fff);
transform: rotate(-45deg);
transform-origin: left center;
animation: meteor-fall 5s infinite;
opacity: 0;
}
/* 创建多个流星 */
.meteor:nth-child(8) {
top: 10%;
left: 50%;
animation-delay: 0s;
}
.meteor:nth-child(9) {
top: 30%;
left: 60%;
animation-delay: 3s;
}
.meteor:nth-child(10) {
top: 50%;
left: 30%;
animation-delay: 6s;
}
.meteor:nth-child(11) {
top: 70%;
left: 80%;
animation-delay: 9s;
}
.meteor:nth-child(12) {
top: 20%;
left: 20%;
animation-delay: 12s;
}
.meteor::after {
content: '';
position: absolute;
right: 0;
top: 0;
width: 10px;
height: 10px;
background: white;
border-radius: 50%;
box-shadow: 0 0 10px 3px white;
}
@keyframes twinkle {
0% { opacity: 0.3; }
100% { opacity: 1; }
}
@keyframes meteor-fall {
0% {
transform: rotate(-45deg) translateX(0);
opacity: 0;
}
10% {
opacity: 1;
}
70% {
opacity: 1;
}
100% {
transform: rotate(-45deg) translateX(1000px);
opacity: 0;
}
}
/* 插入的链接样式 */
.custom-link {
position: fixed;
bottom: 20px;
right: 20px;
color: rgba(255,255,255,0.7);
text-decoration: none;
font-size: 14px;
background: rgba(0,0,0,0.3);
padding: 8px 15px;
border-radius: 20px;
transition: all 0.3s ease;
}
.custom-link:hover {
color: white;
background: rgba(0,0,0,0.5);
}
</style>
</head>
<body>
<div class="night-sky">
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
<div class="meteor"></div>
<div class="meteor"></div>
<div class="meteor"></div>
<div class="meteor"></div>
<div class="meteor"></div>
</div>
</body>
</html>