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, #004e92);
            overflow: hidden;
            font-family: Arial, sans-serif;
        }
        
        .eclipse-container {
            position: relative;
            width: 500px;
            height: 500px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        /* 太阳 */
        .sun {
            position: absolute;
            width: 200px;
            height: 200px;
            background: radial-gradient(circle, #ffde00, #ff8c00);
            border-radius: 50%;
            box-shadow: 0 0 50px #ff8c00, 0 0 100px #ff4500;
            z-index: 1;
            animation: sun-glow 4s ease-in-out infinite alternate;
        }
        
        @keyframes sun-glow {
            0%, 100% {
                box-shadow: 0 0 50px #ff8c00, 0 0 100px #ff4500;
            }
            50% {
                box-shadow: 0 0 70px #ff8c00, 0 0 140px #ff4500;
            }
        }
        
        /* 月亮 */
        .moon {
            position: absolute;
            width: 220px;
            height: 220px;
            background: #000;
            border-radius: 50%;
            z-index: 2;
            animation: eclipse 10s linear infinite;
            transform-origin: center;
        }
        
        @keyframes eclipse {
            0% {
                transform: translateX(-300px) translateY(0);
            }
            40% {
                transform: translateX(0) translateY(0);
            }
            60% {
                transform: translateX(0) translateY(0);
            }
            100% {
                transform: translateX(300px) translateY(0);
            }
        }
        
        /* 日冕效果 */
        .corona {
            position: absolute;
            width: 250px;
            height: 250px;
            border-radius: 50%;
            z-index: 3;
            opacity: 0;
            animation: corona-appear 10s linear infinite;
        }
        
        .corona:before, .corona:after {
            content: '';
            position: absolute;
            width: 100%;
            height: 100%;
            border-radius: 50%;
            background: radial-gradient(circle, transparent 40%, rgba(255,255,255,0.8) 70%, transparent 90%);
        }
        
        .corona:after {
            transform: rotate(45deg);
        }
        
        @keyframes corona-appear {
            0%, 40% {
                opacity: 0;
                transform: scale(0.8);
            }
            45%, 55% {
                opacity: 1;
                transform: scale(1);
            }
            60%, 100% {
                opacity: 0;
                transform: scale(0.8);
            }
        }
        
        /* 星星背景 */
        .stars {
            position: absolute;
            width: 100%;
            height: 100%;
            z-index: 0;
        }
        
        .star {
            position: absolute;
            background: white;
            border-radius: 50%;
            animation: twinkle 2s infinite alternate;
        }
        
        @keyframes twinkle {
            0% {
                opacity: 0.2;
            }
            100% {
                opacity: 1;
            }
        }
        
        /* 底部链接 */
        .footer-link {
            position: absolute;
            bottom: 20px;
            color: rgba(255,255,255,0.7);
            text-decoration: none;
            font-size: 14px;
            transition: opacity 0.3s;
            z-index: 10;
        }
        
        .footer-link:hover {
            color: white;
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="eclipse-container">
        <!-- 星星背景 -->
        <div class="stars" id="stars"></div>
        
        <!-- 太阳 -->
        <div class="sun"></div>
        
        <!-- 月亮 -->
        <div class="moon"></div>
        
        <!-- 日冕 -->
        <div class="corona"></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');
            
            // 随机大小 (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.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、付费专栏及课程。

余额充值