Creates a bouncing loader animation.
<div class="bouncing-loader">
<div></div>
<div></div>
<div></div>
</div>
@keyframes bouncing-loader {
from {
opacity: 1;
transform: translateY(0);
}
to {
opacity: 0.1;
transform: translateY(-1rem);
}
}
.bouncing-loader {
display: flex;
justify-content: center;
}
.bouncing-loader > div {
width: 1rem;
height: 1rem;
margin: 3rem 0.2rem;
background: #8385aa;
border-radius: 50%;
animation: bouncing-loader 0.6s infinite alternate;
}
.bouncing-loader > div:nth-of-type(2) {
animation-delay: 0.2s;
}
.bouncing-loader > div:nth-of-type(3) {
animation-delay: 0.4s;
}
Note: 1rem
is usually 16px
.
-
@keyframes
defines an animation that has two states, where the element changesopacity
, and is translated up on the 2D plane usingtransform: translateY()
. -
.bouncing-loader
is the parent container of the bouncing circles and usesdisplay: flex
andjustify-content: center
to position them in the in the center. -
Using
.bouncing-loader > div
, we target the three childdiv
s of the parent to be styled. Thediv
s are given a width and height of1rem
, usingborder-radius: 50%
to turn them from squares to circles. -
margin: 3rem 0.2rem
specifies that each circle has a top/bottom margin of3rem
and left/right margin of0.2rem
so that they do not directly touch each other, giving them some breathing room. -
animation
is a shorthand property for the various animation properties:animation-name
,animation-duration
,animation-iteration-count
,animation-direction
are used. -
animation-delay
is used on the second and thirddiv
respectively, so that each element does not start the animation at the same time.
✅ No caveats.