CSS3夜晚孔明灯特效

<!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;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(to bottom, #000428, #0a1a3a);
            overflow: hidden;
            font-family: Arial, sans-serif;
        }
        
        .night-sky {
            position: relative;
            width: 100%;
            height: 100vh;
            overflow: hidden;
        }
        
        /* 星星 */
        .stars {
            position: absolute;
            width: 100%;
            height: 100%;
        }
        
        .star {
            position: absolute;
            background: white;
            border-radius: 50%;
            animation: twinkle 2s infinite alternate;
        }
        
        @keyframes twinkle {
            0% { opacity: 0.2; }
            100% { opacity: 1; }
        }
        
        /* 月亮 */
        .moon {
            position: absolute;
            width: 80px;
            height: 80px;
            background: #f5f5dc;
            border-radius: 50%;
            top: 50px;
            right: 100px;
            box-shadow: 0 0 30px #f5f5dc;
        }
        
        /* 孔明灯 */
        .lantern {
            position: absolute;
            animation: float-up 15s linear infinite;
        }
        
        .lantern-body {
            width: 40px;
            height: 50px;
            background: #ff6b6b;
            border-radius: 50% 50% 10% 10%;
            position: relative;
            box-shadow: 0 0 20px #ff6b6b;
        }
        
        .lantern-body:before {
            content: '';
            position: absolute;
            width: 30px;
            height: 5px;
            background: #ffcc5c;
            top: 10px;
            left: 5px;
            border-radius: 5px;
        }
        
        .lantern-body:after {
            content: '';
            position: absolute;
            width: 20px;
            height: 5px;
            background: #ffcc5c;
            bottom: 5px;
            left: 10px;
            border-radius: 5px;
        }
        
        .lantern-string {
            position: absolute;
            width: 2px;
            height: 30px;
            background: #333;
            top: 50px;
            left: 19px;
        }
        
        .lantern-basket {
            position: absolute;
            width: 20px;
            height: 10px;
            background: #8d6e63;
            top: 80px;
            left: 10px;
            border-radius: 0 0 5px 5px;
        }
        
        .lantern-fire {
            position: absolute;
            width: 10px;
            height: 15px;
            background: #ff9e2c;
            border-radius: 50% 50% 20% 20%;
            top: 70px;
            left: 15px;
            box-shadow: 0 0 10px #ff5722;
            animation: flicker 1s ease-in-out infinite alternate;
        }
        
        @keyframes float-up {
            0% {
                transform: translateY(100vh) translateX(var(--start-x));
                opacity: 0;
            }
            10% {
                opacity: 1;
            }
            90% {
                opacity: 1;
            }
            100% {
                transform: translateY(-100px) translateX(var(--end-x));
                opacity: 0;
            }
        }
        
        @keyframes flicker {
            0%, 100% { transform: scale(1); opacity: 1; }
            50% { transform: scale(1.1); opacity: 0.8; }
        }
        
        /* 底部链接 */
        .footer-link {
            position: fixed;
            bottom: 20px;
            color: rgba(255,255,255,0.7);
            text-decoration: none;
            font-size: 14px;
            transition: all 0.3s;
            z-index: 100;
        }
        
        .footer-link:hover {
            color: #ff6b6b;
            text-shadow: 0 0 10px #ff6b6b;
        }
    </style>
</head>
<body>
    <div class="night-sky">
        <div class="moon"></div>
        
        <div class="stars" id="stars"></div>
        
        <!-- 孔明灯 -->
        <div class="lantern" style="--start-x: 10vw; --end-x: 5vw; left: 10%; animation-delay: 0s;">
            <div class="lantern-body"></div>
            <div class="lantern-string"></div>
            <div class="lantern-basket"></div>
            <div class="lantern-fire"></div>
        </div>
        
        <div class="lantern" style="--start-x: 20vw; --end-x: -5vw; left: 30%; animation-delay: 3s;">
            <div class="lantern-body" style="background: #ff9e2c; box-shadow: 0 0 20px #ff9e2c;"></div>
            <div class="lantern-string"></div>
            <div class="lantern-basket"></div>
            <div class="lantern-fire"></div>
        </div>
        
        <div class="lantern" style="--start-x: -10vw; --end-x: 5vw; left: 50%; animation-delay: 6s;">
            <div class="lantern-body" style="background: #ff5252; box-shadow: 0 0 20px #ff5252;"></div>
            <div class="lantern-string"></div>
            <div class="lantern-basket"></div>
            <div class="lantern-fire"></div>
        </div>
        
        <div class="lantern" style="--start-x: 15vw; --end-x: -10vw; left: 70%; animation-delay: 9s;">
            <div class="lantern-body" style="background: #ff4081; box-shadow: 0 0 20px #ff4081;"></div>
            <div class="lantern-string"></div>
            <div class="lantern-basket"></div>
            <div class="lantern-fire"></div>
        </div>
        
        <div class="lantern" style="--start-x: -5vw; --end-x: 10vw; left: 90%; animation-delay: 12s;">
            <div class="lantern-body" style="background: #e91e63; box-shadow: 0 0 20px #e91e63;"></div>
            <div class="lantern-string"></div>
            <div class="lantern-basket"></div>
            <div class="lantern-fire"></div>
        </div>
        

    </div>

    <script>
        // 生成星星
        const starsContainer = document.getElementById('stars');
        const starCount = 100;
        
        for (let i = 0; i < starCount; i++) {
            const star = document.createElement('div');
            star.classList.add('star');
            
            // 随机大小
            const size = Math.random() * 3 + 1;
            star.style.width = `${size}px`;
            star.style.height = `${size}px`;
            
            // 随机位置
            star.style.left = `${Math.random() * 100}%`;
            star.style.top = `${Math.random() * 100}%`;
            
            // 随机动画延迟
            star.style.animationDelay = `${Math.random() * 2}s`;
            
            starsContainer.appendChild(star);
        }
    </script>
</body>
</html>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值