纯CSS3音乐均衡器动画特效

<!DOCTYPE html>
<html lang="zh">
<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;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background: linear-gradient(135deg, #1a1a2e, #16213e);
            overflow: hidden;
            font-family: Arial, sans-serif;
        }
        
        .equalizer-container {
            display: flex;
            align-items: flex-end;
            height: 300px;
            padding: 20px;
            background: rgba(0, 0, 0, 0.3);
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
        }
        
        .bar-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin: 0 10px;
        }
        
        .bar {
            width: 30px;
            background: linear-gradient(to top, #00b4db, #0083b0);
            border-radius: 5px 5px 0 0;
            margin-bottom: 5px;
            box-shadow: 0 0 10px rgba(0, 180, 219, 0.5);
            animation: equalize 1.5s ease infinite alternate;
        }
        
        .bar:nth-child(1) { height: 40px; animation-delay: -0.2s; }
        .bar:nth-child(2) { height: 80px; animation-delay: -0.4s; }
        .bar:nth-child(3) { height: 120px; animation-delay: -0.6s; }
        .bar:nth-child(4) { height: 160px; animation-delay: -0.8s; }
        .bar:nth-child(5) { height: 200px; animation-delay: -1.0s; }
        .bar:nth-child(6) { height: 160px; animation-delay: -1.2s; }
        .bar:nth-child(7) { height: 120px; animation-delay: -1.4s; }
        .bar:nth-child(8) { height: 80px; animation-delay: -1.6s; }
        .bar:nth-child(9) { height: 40px; animation-delay: -1.8s; }
        
        .base {
            width: 50px;
            height: 10px;
            background: #333;
            border-radius: 0 0 5px 5px;
        }
        
        .controls {
            position: absolute;
            bottom: 30px;
            display: flex;
            gap: 20px;
        }
        
        .control-btn {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background: rgba(0, 180, 219, 0.7);
            border: none;
            color: white;
            font-size: 20px;
            cursor: pointer;
            box-shadow: 0 0 10px rgba(0, 180, 219, 0.5);
            transition: all 0.3s;
        }
        
        .control-btn:hover {
            background: rgba(0, 180, 219, 1);
            transform: scale(1.1);
        }
        
        .title {
            position: absolute;
            top: 30px;
            color: white;
            font-size: 24px;
            text-shadow: 0 0 10px rgba(0, 180, 219, 0.8);
        }
        
        .link {
            position: absolute;
            bottom: 20px;
            right: 20px;
            color: #00b4db;
            font-size: 14px;
            text-decoration: none;
            font-weight: bold;
        }
        
        @keyframes equalize {
            0%, 100% {
                height: 10px;
            }
            50% {
                height: var(--random-height);
            }
        }
        
        /* 添加一些背景音乐元素效果 */
        .music-note {
            position: absolute;
            color: rgba(0, 180, 219, 0.7);
            font-size: 24px;
            animation: float-note 4s linear infinite;
            opacity: 0;
        }
        
        @keyframes float-note {
            0% {
                transform: translateY(0) rotate(0deg);
                opacity: 0;
            }
            10% {
                opacity: 1;
            }
            90% {
                opacity: 1;
            }
            100% {
                transform: translateY(-200px) rotate(360deg);
                opacity: 0;
            }
        }
    </style>
</head>
<body>
    <h1 class="title">CSS3音乐均衡器</h1>
    
    <div class="equalizer-container">
        <div class="bar-container">
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="base"></div>
        </div>
        
        <div class="bar-container">
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="base"></div>
        </div>
        
        <div class="bar-container">
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="base"></div>
        </div>
    </div>
    
    <div class="controls">
        <button class="control-btn">▶</button>
        <button class="control-btn">⏸</button>
        <button class="control-btn">⏹</button>
    </div>
    
    
    <script>
        // 为每个均衡器条设置随机高度
        document.querySelectorAll('.bar').forEach(bar => {
            const randomHeight = Math.floor(Math.random() * 200) + 20;
            bar.style.setProperty('--random-height', `${randomHeight}px`);
            
            // 为每个条设置不同的动画延迟
            const randomDelay = Math.random() * 2;
            bar.style.animationDelay = `-${randomDelay}s`;
        });
        
        // 创建漂浮的音符
        function createMusicNote() {
            const note = document.createElement('div');
            note.className = 'music-note';
            note.textContent = '♪';
            note.style.left = `${Math.random() * 100}%`;
            note.style.bottom = '20%';
            note.style.animationDuration = `${Math.random() * 3 + 2}s`;
            document.body.appendChild(note);
            
            setTimeout(() => {
                note.remove();
            }, 4000);
        }
        
        // 定期创建音符
        setInterval(createMusicNote, 800);
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值