Profile Image Moving Up and Down
Now let's make the profile photo move infinitely up and down.
We define a @keyframes named bounce and add bounce 1s infinite alternate to the profile-image class as shown below.
/* Define the bounce animation */ @keyframes bounce { from { transform: translateY(0px); /* Starting position */ } to { transform: translateY(-10px); /* End position */ } } /* Apply the bounce animation */ .profile-image { width: 150px; height: 150px; border-radius: 50%; /* The bounce animation will repeat infinitely every 1 second, alternating directions */ animation: bounce 1s infinite alternate; }
bounce 1s infinite alternate works as follows.
-
@keyframes bounce: Defines an animation named bounce. This animation makes the element appear to bounce by applying specific transformations. -
fromandto: Define the starting and ending stages of the bounce animation.fromspecifies the start point of the animation, andtospecifies the end point. At each stage, thetransformproperty is used to move the element vertically.translateY(0px)indicates the original position of the element, whiletranslateY(-10px)means the element is moved 10 pixels upward. -
In the
.profile-imageclass, theanimationproperty is used to make the bounce animation last for 1 second and repeat infinitely, with theinfiniteattribute. Thealternateattribute makes the animation play forward and then backward in an alternating manner, creating a more natural up and down movement.
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help