抖动天空特效

用JS和CSS实现抖动天空特效

<!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;
            overflow: hidden;
            background: linear-gradient(to bottom, #1e90ff 0%, #87cefa 100%);
            height: 100vh;
            position: relative;
        }
        
        .cloud {
            position: absolute;
            background: white;
            border-radius: 50%;
            opacity: 0.8;
            filter: blur(5px);
        }
        
        .sun {
            position: absolute;
            width: 100px;
            height: 100px;
            background: radial-gradient(circle, #ffff00 30%, #ff8c00 100%);
            border-radius: 50%;
            top: 20%;
            left: 15%;
            box-shadow: 0 0 50px #ffff00;
        }
        
        .link {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            color: white;
            font-family: Arial, sans-serif;
            text-decoration: none;
            font-size: 14px;
            z-index: 100;
        }
    </style>
</head>
<body>
    <div class="sun"></div>
    <!-- 云朵将由JS动态生成 -->
    

    
    <script>
        // 创建云朵
        function createClouds() {
            const cloudCount = 15;
            for (let i = 0; i < cloudCount; i++) {
                const cloud = document.createElement('div');
                cloud.className = 'cloud';
                
                // 随机大小
                const size = Math.random() * 100 + 50;
                cloud.style.width = `${size}px`;
                cloud.style.height = `${size * 0.6}px`;
                
                // 随机位置
                cloud.style.left = `${Math.random() * 100}%`;
                cloud.style.top = `${Math.random() * 70}%`;
                
                document.body.appendChild(cloud);
            }
        }
        
        // 抖动效果
        function shakeSky() {
            const intensity = 2;
            const x = (Math.random() - 0.5) * intensity;
            const y = (Math.random() - 0.5) * intensity;
            
            document.body.style.transform = `translate(${x}px, ${y}px)`;
            
            // 云朵轻微移动
            const clouds = document.querySelectorAll('.cloud');
            clouds.forEach(cloud => {
                const cloudX = (Math.random() - 0.5) * 1;
                const cloudY = (Math.random() - 0.5) * 1;
                const currentLeft = parseFloat(cloud.style.left);
                const currentTop = parseFloat(cloud.style.top);
                
                cloud.style.left = `${currentLeft + cloudX * 0.05}%`;
                cloud.style.top = `${currentTop + cloudY * 0.05}%`;
            });
            
            requestAnimationFrame(shakeSky);
        }
        
        // 初始化
        window.onload = function() {
            createClouds();
            setTimeout(() => {
                shakeSky();
            }, 1000);
        };
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值