<div class="container"> <h1>SOUND WAVE</h1> <div class="wave-container" id="waveContainer"> <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="bar"></div> </div> <div class="controls"> <button id="playPauseBtn">Pause</button> <button id="resetBtn">Reset</button> </div> </div>
* { margin: 0; padding: 0; box-sizing: border-box; } body { min-height: 100vh; display: flex; justify-content: center; align-items: center; background: linear-gradient(135deg, #EDCDC2 0%, #f5e5df 100%); font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; overflow: hidden; } .container { text-align: center; } .wave-container { display: flex; align-items: center; justify-content: center; gap: 8px; height: 200px; margin-bottom: 40px; } .bar { width: 6px; background: linear-gradient(180deg, #d4a89a 0%, #c9968a 100%); border-radius: 10px; animation: wave 1.2s ease-in-out infinite; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } .bar:nth-child(1) { animation-delay: 0s; } .bar:nth-child(2) { animation-delay: 0.1s; } .bar:nth-child(3) { animation-delay: 0.2s; } .bar:nth-child(4) { animation-delay: 0.3s; } .bar:nth-child(5) { animation-delay: 0.4s; } .bar:nth-child(6) { animation-delay: 0.5s; } .bar:nth-child(7) { animation-delay: 0.4s; } .bar:nth-child(8) { animation-delay: 0.3s; } .bar:nth-child(9) { animation-delay: 0.2s; } .bar:nth-child(10) { animation-delay: 0.1s; } @keyframes wave { 0%, 100% { height: 30px; } 50% { height: 150px; } } .controls { display: flex; gap: 15px; justify-content: center; } button { padding: 12px 30px; background: #fff; border: 2px solid #d4a89a; border-radius: 25px; color: #8a6d5f; font-size: 16px; font-weight: 600; cursor: pointer; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); } button:hover { background: #d4a89a; color: #fff; transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15); } button:active { transform: translateY(0); } .paused .bar { animation-play-state: paused; } h1 { color: #8a6d5f; font-size: 28px; margin-bottom: 30px; font-weight: 300; letter-spacing: 2px; }
const waveContainer = document.getElementById('waveContainer'); const playPauseBtn = document.getElementById('playPauseBtn'); const resetBtn = document.getElementById('resetBtn'); let isPaused = false; playPauseBtn.addEventListener('click', () => { isPaused = !isPaused; if (isPaused) { waveContainer.classList.add('paused'); playPauseBtn.textContent = 'Play'; } else { waveContainer.classList.remove('paused'); playPauseBtn.textContent = 'Pause'; } }); resetBtn.addEventListener('click', () => { const bars = document.querySelectorAll('.bar'); // Remove animation temporarily waveContainer.style.display = 'none'; // Force reflow void waveContainer.offsetWidth; // Restore animation waveContainer.style.display = 'flex'; // Ensure it's playing if (isPaused) { isPaused = false; waveContainer.classList.remove('paused'); playPauseBtn.textContent = 'Pause'; } });
Login to leave a comment
No comments yet. Be the first!
No comments yet. Be the first!