/* Confetti Style */
.confetti {
position: absolute;
top: -10px;
width: 10px;
height: 20px;
border-radius: 5px;
opacity: 1;
z-index: 1000;
animation: fall linear infinite, fadeOut 30s forwards, spin 3s infinite linear;
}
/* Falling animation */
@keyframes fall {
0% { transform: translateY(0) translateX(0); }
100% { transform: translateY(100vh) translateX(calc(-50vw + 100vw * var(--direction))); }
}
/* Random rotation */
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Fade-out effect */
@keyframes fadeOut {
0% { opacity: 1; }
100% { opacity: 0; }
}
function createConfetti() {
const confetti = document.createElement("div");
confetti.classList.add("confetti");
// Random colors
const colors = ["red", "blue", "yellow", "green", "purple", "orange"];
confetti.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
// Random positioning and size
confetti.style.left = Math.random() * 100 + "vw";
confetti.style.width = Math.random() * 10 + 5 + "px"; // Vary width
confetti.style.height = Math.random() * 20 + 10 + "px"; // Vary height
// Random animation duration
confetti.style.animationDuration = Math.random() * 10 + 10 + "s";
// Random fall direction
confetti.style.setProperty("--direction", Math.random());
document.body.appendChild(confetti);
// Remove confetti after it falls
setTimeout(() => {
confetti.remove();
}, 30000); // Confetti disappears after 30 seconds
}
// Create confetti every 500ms
setInterval(createConfetti, 500);