Introduction
In this lab, we will be exploring the world of CSS animations by creating a bouncing loader animation. This lab is designed to help you understand how to use @keyframes to define animations, how to apply animations to elements using CSS, and how to control the timing and direction of animations. By the end of this lab, you will have a better understanding of how to create engaging and dynamic animations using CSS.
Bouncing Loader
index.html and style.css have already been provided in the VM.
To create a bouncing loader animation:
- Define a
@keyframesanimation that uses theopacityandtransformproperties, with a single axis translation ontransform: translate3d()for better performance. - Create a parent container with the class
.bouncing-loaderthat usesdisplay: flexandjustify-content: centerto center the bouncing circles. - Give the three
<div>elements for the bouncing circles the samewidth,height, andborder-radius: 50%to make them circular. - Apply the
bouncing-loaderanimation to each of the three bouncing circles. - Use a different
animation-delayfor each circle andanimation-direction: alternateto create the appropriate effect.
Here is the HTML code:
<div class="bouncing-loader">
<div></div>
<div></div>
<div></div>
</div>
And here is the CSS code:
@keyframes bouncing-loader {
to {
opacity: 0.1;
transform: translate3d(0, -16px, 0);
}
}
.bouncing-loader {
display: flex;
justify-content: center;
}
.bouncing-loader > div {
width: 16px;
height: 16px;
margin: 3rem 0.2rem;
background: #8385aa;
border-radius: 50%;
animation: bouncing-loader 0.6s infinite alternate;
}
.bouncing-loader > div:nth-child(2) {
animation-delay: 0.2s;
}
.bouncing-loader > div:nth-child(3) {
animation-delay: 0.4s;
}
Please click on 'Go Live' in the bottom right corner to run the web service on port 8080. Then, you can refresh the Web 8080 Tab to preview the web page.
Summary
Congratulations! You have completed the Bouncing Loader lab. You can practice more labs in LabEx to improve your skills.