Falling Stars - MeggiTools
Run
Toggle Theme
Share Link
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Falling Stars</title> <style> body { margin: 0; overflow: hidden; background: #000; height: 100vh; display: flex; justify-content: center; align-items: center; color: white; font-family: 'Arial', sans-serif; } .container { position: relative; width: 100%; height: 100%; } .star { position: absolute; top: -50px; animation: fall linear infinite; font-size: 1.5rem; will-change: transform; color: yellow; } @keyframes fall { 0% { transform: translateY(0) rotate(0); opacity: 1; } 100% { transform: translateY(100vh) rotate(360deg); opacity: 0; } } .star:nth-child(odd) { animation-duration: 8s; } .star:nth-child(even) { animation-duration: 12s; } </style> </head> <body> <div class="container"> <!-- Falling stars will be inserted here by JavaScript --> </div> <script> const container = document.querySelector('.container'); const stars = ['⭐', '🌟']; function createStar() { const star = document.createElement('div'); star.classList.add('star'); star.textContent = stars[Math.floor(Math.random() * stars.length)]; star.style.left = `${Math.random() * 100}vw`; container.appendChild(star); star.addEventListener('animationend', () => { star.remove(); }); } function createStars() { setInterval(() => { createStar(); }, 400); } createStars(); </script> </body> </html>