Day # 62: Rain animation
Animations are great tools to learn CSS fundamentals. They allow you to add a necessary amount of fun to the challenging process of learning how to code.
Animating rains is always a delightful task to practice animations in CSS. For today’s website, I decided to create an animation that mimics a rain of colored drops. The key here is generating those elements through Javascript and then animating them through CSS in a random way.
First, we style the elements generated in Javascript:
i {
position: absolute;
height: 200px;
background: linear-gradient(transparent, #fff);
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
animation: animate 5s linear infinite;
}
Secondly, we style those elements by separating one from another:
i:nth-child(3n + 1) {
background: linear-gradient(transparent, darkviolet);
}
And lastly, we configure the animation:
@keyframes animate {
0% {
transform: translateY(-200px);
}
100% {
transform: translateY(calc(100vh + 200px));
}
}
Comments
Post a Comment