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: #f0f0f0;
            font-family: Arial, sans-serif;
            overflow: hidden;
        }

        .container {
            text-align: center;
            position: relative;
        }

        .title {
            font-size: 2.5em;
            color: #333;
            margin-bottom: 50px;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
        }

        .explode-btn {
            position: relative;
            padding: 15px 40px;
            font-size: 1.2em;
            background: linear-gradient(45deg, #FF416C, #FF4B2B);
            color: white;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            outline: none;
            box-shadow: 0 5px 15px rgba(255, 75, 43, 0.4);
            transition: all 0.3s;
            overflow: hidden;
            z-index: 1;
        }

        .explode-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(255, 75, 43, 0.6);
        }

        .explode-btn:active {
            transform: translateY(1px);
        }

        .explode-btn.clicked {
            animation: btnShrink 0.5s forwards;
        }

        .particles {
            position: absolute;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            pointer-events: none;
            z-index: 2;
        }

        .link {
            position: absolute;
            bottom: 30px;
            left: 0;
            width: 100%;
            text-align: center;
        }

        .link a {
            color: #FF416C;
            text-decoration: none;
            font-weight: bold;
            padding: 8px 15px;
            border-radius: 20px;
            transition: all 0.3s;
        }

        .link a:hover {
            background: rgba(255, 65, 108, 0.1);
        }

        @keyframes btnShrink {
            0% {
                transform: scale(1);
                opacity: 1;
            }
            100% {
                transform: scale(0);
                opacity: 0;
            }
        }

        @keyframes particleFly {
            0% {
                transform: translate(0, 0) scale(1);
                opacity: 1;
            }
            100% {
                transform: translate(var(--tx), var(--ty)) scale(0);
                opacity: 0;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1 class="title">点击按钮看爆炸效果</h1>
        <button class="explode-btn" id="explodeBtn">点击爆炸</button>
        
        <div class="link">
         
        </div>
    </div>

    <script>
        document.getElementById('explodeBtn').addEventListener('click', function(e) {
            const btn = e.target;
            btn.classList.add('clicked');
            
            // 创建爆炸粒子
            createParticles(btn);
            
            // 重置按钮状态
            setTimeout(() => {
                btn.classList.remove('clicked');
            }, 500);
        });

        function createParticles(btn) {
            const btnRect = btn.getBoundingClientRect();
            const centerX = btnRect.left + btnRect.width / 2;
            const centerY = btnRect.top + btnRect.height / 2;
            
            // 创建30个粒子
            for (let i = 0; i < 30; i++) {
                const particle = document.createElement('div');
                particle.className = 'particles';
                
                // 随机颜色
                const hue = Math.floor(Math.random() * 60) + 10; // 10-70红色到橙色
                particle.style.backgroundColor = `hsl(${hue}, 100%, 50%)`;
                
                // 随机大小
                const size = Math.random() * 10 + 5;
                particle.style.width = `${size}px`;
                particle.style.height = `${size}px`;
                
                // 随机位置
                const angle = Math.random() * Math.PI * 2;
                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 = `${centerX}px`;
                particle.style.top = `${centerY}px`;
                
                // 动画
                particle.style.animation = `particleFly 0.8s ease-out forwards`;
                
                document.body.appendChild(particle);
                
                // 动画结束后移除粒子
                setTimeout(() => {
                    particle.remove();
                }, 800);
            }
        }
    </script>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值