水面上的月亮CSS3动画特效

<!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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值