JS+CSS3波纹催眠动画特效

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS+CSS3波纹催眠动画特效</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            overflow: hidden;
            background-color: #1a1a2e;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            font-family: Arial, sans-serif;
        }
        
        .container {
            position: relative;
            width: 100%;
            height: 100%;
        }
        
        .ripple {
            position: absolute;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
            transform: scale(0);
            animation: ripple 6s infinite;
            pointer-events: none;
        }
        
        @keyframes ripple {
            to {
                transform: scale(4);
                opacity: 0;
            }
        }
        
        .text {
            position: absolute;
            color: white;
            font-size: 24px;
            text-align: center;
            z-index: 100;
            text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
            animation: pulse 3s infinite alternate;
        }
        
        @keyframes pulse {
            from {
                opacity: 0.7;
                transform: scale(0.95);
            }
            to {
                opacity: 1;
                transform: scale(1.05);
            }
        }
        
        .link {
            position: absolute;
            bottom: 20px;
            color: rgba(255, 255, 255, 0.7);
            font-size: 14px;
            text-decoration: none;
            z-index: 100;
        }
    </style>
</head>
<body>
    <div class="container" id="rippleContainer">
        <div class="text">深呼吸<br>放松心情<br>跟随波纹节奏</div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const container = document.getElementById('rippleContainer');
            const colors = [
                'rgba(100, 149, 237, 0.3)',
                'rgba(152, 251, 152, 0.3)',
                'rgba(255, 105, 180, 0.3)',
                'rgba(255, 255, 0, 0.3)',
                'rgba(138, 43, 226, 0.3)'
            ];
            
            function createRipple() {
                const ripple = document.createElement('div');
                ripple.className = 'ripple';
                
                // 随机大小
                const size = Math.random() * 200 + 100;
                ripple.style.width = `${size}px`;
                ripple.style.height = `${size}px`;
                
                // 随机位置
                const x = Math.random() * (window.innerWidth - size);
                const y = Math.random() * (window.innerHeight - size);
                ripple.style.left = `${x}px`;
                ripple.style.top = `${y}px`;
                
                // 随机颜色
                const color = colors[Math.floor(Math.random() * colors.length)];
                ripple.style.background = color;
                ripple.style.borderColor = color.replace('0.3', '0.6');
                
                // 随机动画延迟
                ripple.style.animationDelay = `${Math.random() * 2}s`;
                
                container.appendChild(ripple);
                
                // 动画结束后移除元素
                setTimeout(() => {
                    ripple.remove();
                }, 6000);
            }
            
            // 初始创建一些波纹
            for (let i = 0; i < 5; i++) {
                setTimeout(createRipple, i * 1200);
            }
            
            // 定时创建新波纹
            setInterval(createRipple, 1500);
            
            // 点击也可以创建波纹
            container.addEventListener('click', function(e) {
                const ripple = document.createElement('div');
                ripple.className = 'ripple';
                
                const size = 150;
                ripple.style.width = `${size}px`;
                ripple.style.height = `${size}px`;
                
                ripple.style.left = `${e.clientX - size/2}px`;
                ripple.style.top = `${e.clientY - size/2}px`;
                
                const color = colors[Math.floor(Math.random() * colors.length)];
                ripple.style.background = color;
                ripple.style.borderColor = color.replace('0.3', '0.6');
                
                container.appendChild(ripple);
                
                setTimeout(() => {
                    ripple.remove();
                }, 6000);
            });
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值