<!DOCTYPE html>
<html lang="zh">
<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;
overflow: hidden;
background: linear-gradient(to bottom, #0a0a2a, #1a1a4a, #2a2a6a);
display: flex;
justify-content: center;
align-items: center;
font-family: Arial, sans-serif;
}
.container {
position: relative;
width: 100%;
height: 100%;
}
.moon {
position: absolute;
top: 20%;
left: 50%;
transform: translateX(-50%);
width: 100px;
height: 100px;
background: #f5f5dc;
border-radius: 50%;
box-shadow: 0 0 30px #fff, 0 0 60px #fff, 0 0 90px #fff;
animation: float 8s ease-in-out infinite;
}
.water {
position: absolute;
bottom: 0;
width: 100%;
height: 40%;
background: linear-gradient(to bottom, transparent, rgba(0, 100, 255, 0.3));
border-top: 1px solid rgba(255, 255, 255, 0.2);
animation: wave 10s linear infinite;
}
.moon-reflection {
position: absolute;
bottom: 20%;
left: 50%;
transform: translateX(-50%);
width: 80px;
height: 20px;
background: rgba(245, 245, 220, 0.3);
border-radius: 50%;
filter: blur(5px);
animation: reflect 8s ease-in-out infinite, wave 10s linear infinite;
}
.stars {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.star {
position: absolute;
background: white;
border-radius: 50%;
animation: twinkle 1s infinite alternate;
}
@keyframes float {
0%, 100% {
transform: translateX(-50%) translateY(0);
}
50% {
transform: translateX(-50%) translateY(-20px);
}
}
@keyframes wave {
0% {
transform: skewY(0deg);
}
50% {
transform: skewY(2deg);
}
100% {
transform: skewY(0deg);
}
}
@keyframes reflect {
0%, 100% {
transform: translateX(-50%) scaleY(1);
opacity: 0.6;
}
50% {
transform: translateX(-50%) scaleY(0.8);
opacity: 0.3;
}
}
@keyframes twinkle {
0% {
opacity: 0.2;
}
100% {
opacity: 1;
}
}
.link {
position: absolute;
bottom: 10px;
right: 10px;
color: white;
font-size: 12px;
text-decoration: none;
}
</style>
</head>
<body>
<div class="container">
<div class="stars" id="stars"></div>
<div class="moon"></div>
<div class="moon-reflection"></div>
<div class="water"></div>
</div>
<script>
// 创建星星
const starsContainer = document.getElementById('stars');
for (let i = 0; i < 100; i++) {
const star = document.createElement('div');
star.classList.add('star');
// 随机大小
const size = Math.random() * 2;
star.style.width = `${size}px`;
star.style.height = `${size}px`;
// 随机位置
star.style.left = `${Math.random() * 100}%`;
star.style.top = `${Math.random() * 70}%`;
// 随机闪烁延迟
star.style.animationDelay = `${Math.random() * 2}s`;
starsContainer.appendChild(star);
}
</script>
</body>
</html>