CSS Property animation-fill-mode

The Associate in Nursingimation-fill-mode property defines what values area unit applied by an animation outside the time it’s capital punishment. a lot of specifically, it defines what designs area unit applied to the component throughout the animation delay time, and when the animation has finished execution.

By default, Associate in Nursing animation won’t have an effect on property values between the time it’s applied (the animation-name property is ready on a part, or the animation shorthand property) and therefore the time it begins execution (which is set by the animation-delay property). Also, by default Associate in Nursing animation doesn’t have an effect on property values when the animation finishs (the end of the animation is set by the animation-duration and animation-iteration-count properties). The animation-fill-mode property will override this behavior.

A CSS animations won’t have an effect on the component you’re invigorating till the primary keyframe is “played”, then stops touching it once the last keyframe has completed. this may leave you with some awkward jumps and cuts. you’ll be able to use animation-fill-mode to sleek the transitions into the animation designs and out of doors them, once the animation is finished taking part in.

You can “prepare” your component for the animation by applying the varieties of the primary animation keyframe to the component, whereas the component is looking ahead to the animation to begin, that is sometimes throughout the animation delay time; that’s, when you’ve applied the animation to the component, however before it really starts taking part in. this may forestall a unexpected jump from the initial state of the component to the primary state within the animation, if the latter isn’t a similar because the initial state.

You can even have the component keep the designs applied to that at the top of the animation within the last keyframe, once the animation is finished. this can be sometimes helpful to stop a “jump” back to the initial designs. for instance, if you’re invigorating a ball by moving it from one facet to a different, you’ll wish it to stay at its new position, and not jump back to its initial position once the animation is over. this can be wherever the animation-fill-mode property conjointly helps.

You can conjointly do each of the above: apply the varieties of the start of the animation to the component before the animation begins (in the delay time) and have the component keep the ultimate designs applied by the animation once it’s finished. These area unit sometimes easier to grasp with a live example, thus ensure you check the live demo section below for a live example.

You can specify one or multiple comma-separated animation-fill-mode values. after you offer a listing of comma-separated values, this list is sometimes mapped to a listing of animations nominative exploitation the animation-name property.

For example, if you offer 2 animation-fill-mode values, then the primary worth determines the fill mode of the primary animation within the list of animation names provided by animation-name, and therefore the second fill mode specifies the fill mode of the second animation.

The animation-fill-mode property is sometimes nominative as a part of the animation shorthand property.

Examples

.class{
    animation-name: first-animation, second-animation;
    animation-duration: 2s, 4s;
    animation-delay: 2s, 0s;
    animation-fill-mode: both, forwards;
    animation-timing-function: ease-in, steps(3, start);
}

Desktop Browser Support

Mobile Browser Support

Leave a Reply