按钮点击水波纹效果

<!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>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Arial', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-color: #f5f5f5;
            flex-direction: column;
        }
        
        .container {
            text-align: center;
            max-width: 800px;
            padding: 20px;
        }
        
        h1 {
            margin-bottom: 40px;
            color: #333;
        }
        
        .btn-ripple-container {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 20px;
            margin-bottom: 40px;
        }
        
        .btn {
            position: relative;
            overflow: hidden;
            padding: 12px 24px;
            background: #4a89dc;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
            outline: none;
            transition: all 0.3s;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
            min-width: 120px;
        }
        
        .btn:hover {
            background: #3b7dd8;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }
        
        .btn:active {
            transform: translateY(0);
            box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
        }
        
        .btn .ripple {
            position: absolute;
            border-radius: 50%;
            background-color: rgba(255, 255, 255, 0.7);
            transform: scale(0);
            animation: ripple 0.6s linear;
            pointer-events: none;
        }
        
        @keyframes ripple {
            to {
                transform: scale(4);
                opacity: 0;
            }
        }
        
        /* 不同颜色的按钮 */
        .btn-primary {
            background: #4a89dc;
        }
        
        .btn-success {
            background: #48cfad;
        }
        
        .btn-warning {
            background: #ffce54;
            color: #333;
        }
        
        .btn-danger {
            background: #ed5565;
        }
        
        .btn-info {
            background: #5d9cec;
        }
        
        .btn-dark {
            background: #434a54;
        }
        
        .footer {
            margin-top: 50px;
            color: #666;
            font-size: 14px;
        }
        
        .footer a {
            color: #4a89dc;
            text-decoration: none;
        }
        
        .footer a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>按钮点击水波纹效果</h1>
        
        <div class="btn-ripple-container">
            <button class="btn btn-primary">主要按钮</button>
            <button class="btn btn-success">成功按钮</button>
            <button class="btn btn-warning">警告按钮</button>
            <button class="btn btn-danger">危险按钮</button>
            <button class="btn btn-info">信息按钮</button>
            <button class="btn btn-dark">深色按钮</button>
        </div>
        
        <p>点击上面的按钮查看水波纹效果</p>
        
        <div class="footer">

        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const buttons = document.querySelectorAll('.btn');
            
            buttons.forEach(button => {
                button.addEventListener('click', function(e) {
                    // 移除之前的水波纹元素
                    const ripples = this.querySelectorAll('.ripple');
                    ripples.forEach(ripple => {
                        ripple.remove();
                    });
                    
                    // 获取点击位置
                    const rect = this.getBoundingClientRect();
                    const x = e.clientX - rect.left;
                    const y = e.clientY - rect.top;
                    
                    // 创建水波纹元素
                    const ripple = document.createElement('span');
                    ripple.classList.add('ripple');
                    ripple.style.left = `${x}px`;
                    ripple.style.top = `${y}px`;
                    ripple.style.width = `${Math.max(rect.width, rect.height)}px`;
                    ripple.style.height = `${Math.max(rect.width, rect.height)}px`;
                    
                    this.appendChild(ripple);
                    
                    // 动画结束后移除水波纹元素
                    setTimeout(() => {
                        ripple.remove();
                    }, 600);
                });
            });
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值