-
Speed Meter Animation
HTML
CSS
JavaScript
0
body { margin: 0; height: 100vh; background: #020617; display: flex; align-items: center; justify-content: center; overflow: hidden; font-family: Arial, sans-serif; } /* MULTICOLOR GLOW */ .glow-bg { position: absolute; width: 650px; height: 650px; border-radius: 50%; background: conic-gradient( red, orange, yellow, lime, cyan, blue, violet, red ); filter: blur(80px); opacity: 0; transform: scale(0.6); transition: all 0.6s ease; } /* ACTIVE STATE */ .glow-bg.active { opacity: 0.8; transform: scale(1.2); animation: rotateGlow 6s linear infinite, pulseGlow 2s ease-in-out infinite; } /* Rotation */ @keyframes rotateGlow { from { transform: rotate(0deg) scale(1.2); } to { transform: rotate(360deg) scale(1.2); } } /* Pulse */ @keyframes pulseGlow { 0% { opacity: 0.5; } 50% { opacity: 0.9; } 100% { opacity: 0.5; } } /* Meter */ .meter { position: relative; width: 300px; height: 300px; border-radius: 50%; background: radial-gradient(circle at center, #1e293b, #020617); box-shadow: 0 0 30px rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 2; } /* Scale */ .scale div { position: absolute; width: 3px; height: 18px; background: #38bdf8; top: 10px; left: 50%; transform-origin: center 140px; } /* Needle */ .needle { position: absolute; width: 4px; height: 120px; background: #f43f5e; bottom: 50%; left: 50%; transform-origin: bottom center; transform: rotate(-90deg); box-shadow: 0 0 15px #f43f5e; } /* Center */ .center { position: absolute; width: 14px; height: 14px; background: #fff; border-radius: 50%; } /* Speed text */ .speed { position: absolute; bottom: 30px; font-size: 28px; font-weight: bold; color: #38bdf8; }
const scale = document.getElementById("scale"); for (let i = 0; i <= 180; i += 10) { let tick = document.createElement("div"); tick.style.transform = `rotate(${i - 90}deg)`; scale.appendChild(tick); } let running = false; let speed = 0; let direction = 1; let maxSpeed = 180; function animateSpeed() { if (!running) return; speed += direction * (Math.random() * 2); if (speed >= maxSpeed) direction = -1; if (speed <= 0) direction = 1; const angle = (speed / maxSpeed) * 180 - 90; document.getElementById("needle").style.transform = `rotate(${angle}deg)`; document.getElementById("speedText").innerText = Math.floor(speed) + " km/h"; requestAnimationFrame(animateSpeed); } function toggleLoop() { running = !running; const glow = document.getElementById("glow"); if (running) { glow.classList.add("active"); animateSpeed(); } else { glow.classList.remove("active"); } }
Live Preview