Falling Elements - 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 Elements: CSS Background Animation</title> <style> body { margin: 0; overflow: hidden; background: linear-gradient(to bottom, #1e3c72, #2a5298); height: 100vh; display: flex; justify-content: center; align-items: center; color: white; font-family: 'Arial', sans-serif; } .container { position: relative; width: 100%; height: 100%; } .element { position: absolute; top: -100px; animation: fall linear infinite; font-size: 2rem; will-change: transform; } @keyframes fall { 0% { transform: translateY(0) rotate(0); opacity: 1; } 100% { transform: translateY(100vh) rotate(720deg); opacity: 0; } } .emoji { animation-duration: 10s; } .icon { animation-duration: 15s; } .shape { animation-duration: 20s; } .emoji:nth-child(odd) { animation-duration: 12s; } .icon:nth-child(even) { animation-duration: 18s; } .shape:nth-child(odd) { animation-duration: 22s; } </style> </head> <body> <div class="container"> <!-- Falling elements will be inserted here by JavaScript --> </div> <script> const container = document.querySelector('.container'); const emojis = ['😀', '🎉', '🌟', '🍀', '🔥']; const icons = ['⚙️', '🔧', '💡', '🔋', '🚀']; const shapes = ['🔶', '🔷', '🔺', '🔵', '🔴']; function createFallingElement(content, type) { const element = document.createElement('div'); element.classList.add('element', type); element.textContent = content; element.style.left = `${Math.random() * 100}vw`; container.appendChild(element); element.addEventListener('animationend', () => { element.remove(); }); } function createFallingElements() { setInterval(() => { createFallingElement(emojis[Math.floor(Math.random() * emojis.length)], 'emoji'); createFallingElement(icons[Math.floor(Math.random() * icons.length)], 'icon'); createFallingElement(shapes[Math.floor(Math.random() * shapes.length)], 'shape'); }, 500); } createFallingElements(); </script> </body> </html>