<div class="rain-container">
</div>
:root {
--animation-speed: 2s;
--primary-color: #000;
--secondary-color: #000;
--background-color: #212121;
--text-color: #fff;
--font: sans-serif;
}
* {
margin: 0;
padding: 0;
}
.rain-container {
position: relative;
background: #000;
/* background: url("https://rb.gy/ufafte") no-repeat center center fixed; */
width: 100vw;
height: 100vh;
overflow: hidden;
object-fit: cover;
background-size: cover;
}
i {
position: absolute;
height: 120px;
border-radius: 0 0 999px 999px;
animation: animate 5s linear infinite;
}
@keyframes animate {
0% {
transform: translateY(-120px);
}
100% {
transform: translateY(calc(100vh + 120px));
}
}
const rainContainer = document.querySelector(".rain-container");
// background Colors for the raindrop
const background = [
"linear-gradient(transparent, aqua)",
"linear-gradient(transparent, red)",
"linear-gradient(transparent, limegreen)",
"linear-gradient(transparent, white)",
"linear-gradient(transparent, yellow)"
];
const amount = 100; // amount of raindops
let i = 0;
let drop, raindropProperties;
// Looping and creating the raindrop then adding to the rainContainer
while (i < amount) {
drop = document.createElement("i");
// CSS Properties for raindrop
raindropProperties = {
width: Math.random() * 5 + "px",
positionX: Math.floor(Math.random() * window.innerWidth) + "px",
delay: Math.random() * -20 + "s",
duration: Math.random() * 5 + "s",
bg: background[Math.floor(Math.random() * background.length)],
opacity: Math.random() + 0.2
};
// Setting Styles for raindrop
drop.style.width = raindropProperties.width;
drop.style.left = raindropProperties.positionX;
drop.style.animationDelay = raindropProperties.delay;
drop.style.animationDuration = raindropProperties.duration;
drop.style.background = raindropProperties.bg;
drop.style.opacity = raindropProperties.opacity;
// Appending the raindrop in the raindrop container
rainContainer.appendChild(drop);
i++;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.