点击烟花波纹效果

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>点击烟花波纹效果</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            width: 100vw;
            height: 100vh;
            overflow: hidden;
            cursor: pointer;
            background-color: #121212;
            font-family: Arial, sans-serif;
        }
        
        .ripple {
            position: absolute;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.6);
            transform: scale(0);
            pointer-events: none;
            animation: ripple 1s ease-out;
        }
        
        .particle {
            position: absolute;
            border-radius: 50%;
            pointer-events: none;
            animation: particle 1s ease-out forwards;
        }
        
        @keyframes ripple {
            to {
                transform: scale(3);
                opacity: 0;
            }
        }
        
        @keyframes particle {
            0% {
                transform: translate(0, 0);
                opacity: 1;
            }
            100% {
                transform: translate(var(--tx), var(--ty));
                opacity: 0;
            }
        }
        
        .footer {
            position: fixed;
            bottom: 15px;
            width: 100%;
            text-align: center;
            color: rgba(255, 255, 255, 0.7);
            font-size: 14px;
            z-index: 100;
        }
        
        .footer a {
            color: #ff9800;
            text-decoration: none;
            transition: color 0.3s;
        }
        
        .footer a:hover {
            color: #ff5722;
            text-decoration: underline;
        }
    </style>
</head>
<body>
 

    <script>
        document.addEventListener('click', function(e) {
            createRipple(e.clientX, e.clientY);
            createParticles(e.clientX, e.clientY); // 修复了函数名拼写错误
        });
        
        function createRipple(x, y) {
            const ripple = document.createElement('div');
            ripple.className = 'ripple';
            
            // 随机颜色
            const hue = Math.floor(Math.random() * 360);
            ripple.style.background = `hsla(${hue}, 100%, 70%, 0.6)`;
            
            ripple.style.left = (x - 20) + 'px';
            ripple.style.top = (y - 20) + 'px';
            ripple.style.width = '40px';
            ripple.style.height = '40px';
            
            document.body.appendChild(ripple);
            
            setTimeout(() => {
                ripple.remove();
            }, 1000);
        }
        
        function createParticles(x, y) { // 修复了函数名拼写错误
            const particleCount = 30;
            const angleIncrement = (Math.PI * 2) / particleCount;
            
            for (let i = 0; i < particleCount; i++) {
                const particle = document.createElement('div');
                particle.className = 'particle';
                
                // 随机大小
                const size = Math.random() * 8 + 4;
                particle.style.width = `${size}px`;
                particle.style.height = `${size}px`;
                
                // 随机颜色
                const hue = (Math.floor(Math.random() * 60) + (i % 2 === 0 ? 0 : 180));
                particle.style.background = `hsl(${hue}, 100%, 70%)`;
                
                // 计算粒子运动方向
                const angle = angleIncrement * i;
                const distance = Math.random() * 100 + 50;
                const tx = Math.cos(angle) * distance;
                const ty = Math.sin(angle) * distance;
                
                particle.style.setProperty('--tx', `${tx}px`);
                particle.style.setProperty('--ty', `${ty}px`);
                
                particle.style.left = (x - size/2) + 'px';
                particle.style.top = (y - size/2) + 'px';
                
                document.body.appendChild(particle);
                
                setTimeout(() => {
                    particle.remove();
                }, 1000);
            }
        }
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值