Utilizing Animations
animation-direction and animation-iteration-count
animation-direction
determines the playback direction of an animation.
It allows you to control whether an HTML element spins in one direction like a windmill or oscillates back and forth.
div { animation-direction: alternate; /* Repeats the animation back and forth */ animation-iteration-count: infinite; /* Repeats the animation indefinitely */ }
alternate
plays the animation once and then also in reverse direction.
infinite
repeats the animation endlessly.
Combining :hover with Animation
:hover
defines styles when a mouse is hovering over an element.
By combining this with animation, you can create a dynamic web page that reacts to user actions.
.animated-div:hover { /* Changes background color to red when hovered */ background-color: red; /* Bounce effect when hovered */ animation-name: bounce; /* Lasts for 1 second */ animation-duration: 1s; /* Slightly enlarges when hovered */ transform: scale(1.05); /* Changes cursor to pointer when hovered */ cursor: pointer; }
This way, the animation starts only when the user hovers the mouse over the div
.
What is the role of the animation-direction
property?
Sets the duration of the animation
Sets the number of times the animation will repeat
Sets the direction in which the animation plays
Sets the starting point of the animation
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help