Definition of Animation-fill-mode
Animation-fill-mode is an animation property that defines what happens on the other side of the border with another element when there are two elements side by side acting as one unit. It exists in three separate categories: normal, forwards, and backward.
The Animation Fill Mode property works very much like transform-origin. It is much more useful and practical in certain circumstances than the Animation Origin property. Artists and creators can enhance it further with the animation timing curve; animation-delay, animation duration, animation timing function, and animation acceleration properties.
Developers use animation-fill-mode in conjunction with Animation Delay and Animation Duration properties to ensure synchronization of the animations of two elements. The concept’s full property takes effect only when animation-delay is greater than 0; animation duration is greater than 0, and animation fill mode property has been set to either forward, backward or normal.
Animation-fill-mode property can also be useful in creating a bouncing effect with 3D transform properties. This simple example shows the animation of two containers side by side using the animation-fill-mode property.
How Do We Use Animation-Fill-Mode?
Example 1: Animation-Fill Mode: Backwards In this example, we have an Animation of a spinning circle on top of a blue rectangle, which is set to Animation-fill-mode: backward. When the animation spins clockwise, it uses blue for its background color, and when it spins counterclockwise, it uses red for the background color. The animation runs indefinitely until stopped using Animation-play-state. Example this.
Example 2: Animation-Fill-Mode: Forwards and Backwards Here we have two Sprites stacked on top of each other. The Sprite on the bottom is set to Animation-fill mode: forwards, and the Sprite above it is set to Animation-fill mode: backward, which causes them both to run in opposite directions. This animation runs indefinitely until stopped using Animation-play-state. Example this.
Example 3: Animation-Fill-Mode: Once In this example, we have a repeating Animation of the letter “A” that will repeat infinitely until it is stopped with Animation-play-state. The “A” has different colors from one Animation frame to another. For example, the Animation of the “A” might be red on one frame and green on the next. However, while Animation-fill-mode: once is set for this animation, it will only show up once in a row regardless of how many times Animation-iteration occurs.