Falling Hearts - 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 Hearts</title> <style> body { margin: 0; overflow: hidden; background: #ff69b4; height: 100vh; display: flex; justify-content: center; align-items: center; color: white; font-family: 'Arial', sans-serif; } .container { position: relative; width: 100%; height: 100%; } .heart { position: absolute; top: -50px; animation: fall linear infinite; font-size: 2rem; will-change: transform; color: red; } @keyframes fall { 0% { transform: translateY(0) rotate(0); opacity: 1; } 100% { transform: translateY(100vh) rotate(720deg); opacity: 0; } } .heart:nth-child(odd) { animation-duration: 10s; } .heart:nth-child(even) { animation-duration: 15s; } </style> </head> <body> <div class="container"> <!-- Falling hearts will be inserted here by JavaScript --> </div> <script> const container = document.querySelector('.container'); const hearts = ['❤️', '💖', '💘']; function createHeart() { const heart = document.createElement('div'); heart.classList.add('heart'); heart.textContent = hearts[Math.floor(Math.random() * hearts.length)]; heart.style.left = `${Math.random() * 100}vw`; container.appendChild(heart); heart.addEventListener('animationend', () => { heart.remove(); }); } function createHearts() { setInterval(() => { createHeart(); }, 600); } createHearts(); </script> </body> </html>