Animation

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Animation

List of Content :
1. What is animation

2. @keyframes Rules

3. Delaying an animation

4. Setting how many times an animation can run

5. Run Animation in Reverse Direction or Alternate Cycles

6. Specify the speed Curve of the Animation

7. Specify the fill-mode For an Animation

8. Animation Shorthand Property


What is animation
● An animation lets an element gradually change from one style to another.

● You can change as many CSS properties you want, as many times as you want.

● To use CSS animation, you must first specify some keyframes for the animation.
@keyframes Rules
● When you specify CSS styles inside the @keyframes rule, the animation will
gradually change from the current style to the new style at certain times.

● To get an animation to work, you must bind the animation to an element.

● The animation-duration property defines how long an animation should take to


complete. If the animation-duration property is not specified, no animation will
occur, because the default value is 0s (0 seconds).
Delaying an animation
● The animation-delay property specifies a delay for the start of an animation.

● Animation delay can also have negative values.


Setting how many times an animation
can run
● The animation-iteration-count property specifies the number of times an
animation should run. This can also be infinite.
Run Animation in Reverse Direction or
Alternate Cycles
● The animation-direction property specifies whether an animation should be played
forwards, backwards or in alternate cycles.

● The animation-direction property can have the following values:

normal - The animation is played as normal (forwards). This is default


reverse - The animation is played in reverse direction (backwards)
alternate - The animation is played forwards first, then backwards
alternate-reverse - The animation is played backwards first, then forwards
Specify the speed Curve of the
Animation
The animation-timing-function property specifies the speed curve of the animation.

The animation-timing-function property can have the following values:


● ease - Specifies an animation with a slow start, then fast, then end slowly (this is default)
● linear - Specifies an animation with the same speed from start to end
● ease-in - Specifies an animation with a slow start
● ease-out - Specifies an animation with a slow end
● ease-in-out - Specifies an animation with a slow start and end
● cubic-bezier(n,n,n,n) - Lets you define your own values in a cubic-bezier function
Specify the fill-mode For an Animation
CSS animations do not affect an element before the first keyframe is played or after the last
keyframe is played. The animation-fill-mode property can override this behavior.

The animation-fill-mode property specifies a style for the target element when the
animation is not playing (before it starts, after it ends, or both).

The animation-fill-mode property can have the following values:


● none - Default value. Animation will not apply any styles to the element before or after it
is executing
● forwards - The element will retain the style values that is set by the last keyframe
(depends on animation-direction and animation-iteration-count)
● backwards - The element will get the style values that is set by the first keyframe
(depends on animation-direction), and retain this during the animation-delay period
● both - The animation will follow the rules for both forwards and backwards, extending the
animation properties in both directions.
Animation Shorthand Property
● Look at the animation mentioned in the div below:
div {
animation-name: example;
animation-duration: 5s;
animation-timing-function: linear;
animation-delay: 2s;
animation-iteration-count: infinite;
animation-direction: alternate;

● To achieve this in shorthand we will use the following:


div {
animation: example 5s linear 2s infinite alternate;
}
THANK YOU

You might also like