流星雨动画特效

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>流星雨动画特效</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            background-color: #000;
            overflow: hidden;
            height: 100vh;
            font-family: Arial, sans-serif;
        }
        
        .stars {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 0;
        }
        
        .star {
            position: absolute;
            background-color: #fff;
            border-radius: 50%;
            animation: twinkle var(--duration) infinite ease-in-out;
        }
        
        @keyframes twinkle {
            0%, 100% { opacity: 0.2; }
            50% { opacity: 1; }
        }
        
        .meteor {
            position: absolute;
            width: 2px;
            height: 2px;
            background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 50%, rgba(255,255,255,0) 100%);
            transform: rotate(var(--angle));
            transform-origin: left center;
            animation: meteor var(--speed) linear infinite;
            opacity: 0;
            z-index: 1;
        }
        
        @keyframes meteor {
            0% {
                transform: rotate(var(--angle)) translateX(0);
                opacity: 1;
            }
            70% {
                opacity: 1;
            }
            100% {
                transform: rotate(var(--angle)) translateX(var(--distance));
                opacity: 0;
            }
        }
        
        .info {
            position: fixed;
            bottom: 20px;
            right: 20px;
            color: white;
            z-index: 10;
            font-size: 12px;
            opacity: 0.7;
        }
        
        .info a {
            color: #4fc3f7;
            text-decoration: none;
        }
        
        .info a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="stars" id="stars"></div>

    <script>
        // 创建星星背景
        function createStars() {
            const starsContainer = document.getElementById('stars');
            const starCount = 200;
            
            for (let i = 0; i < starCount; i++) {
                const star = document.createElement('div');
                star.classList.add('star');
                
                // 随机大小 (1-3px)
                const size = Math.random() * 2 + 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.setProperty('--duration', `${Math.random() * 3 + 2}s`);
                
                starsContainer.appendChild(star);
            }
        }
        
        // 创建流星
        function createMeteors() {
            const meteorCount = 10;
            
            for (let i = 0; i < meteorCount; i++) {
                const meteor = document.createElement('div');
                meteor.classList.add('meteor');
                
                // 随机角度 (-60到60度之间)
                const angle = Math.random() * 120 - 60;
                meteor.style.setProperty('--angle', `${angle}deg`);
                
                // 随机速度 (3-8秒)
                const speed = Math.random() * 5 + 3;
                meteor.style.setProperty('--speed', `${speed}s`);
                
                // 随机距离 (1000-2000px)
                const distance = Math.random() * 1000 + 1000;
                meteor.style.setProperty('--distance', `${distance}px`);
                
                // 随机起始位置
                meteor.style.left = `${Math.random() * 100}%`;
                meteor.style.top = `${Math.random() * 100}%`;
                
                // 随机延迟 (0-speed秒)
                meteor.style.animationDelay = `${Math.random() * speed}s`;
                
                document.body.appendChild(meteor);
            }
        }
        
        // 初始化
        window.onload = function() {
            createStars();
            createMeteors();
        };
    </script>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值