Before diving into it, we need to understand the importance of CSS animations
Animation can establish interaction between users and the user interface. This makes your website more interactive which ultimately attracts more visitors to your webpage.
Animation can establish interaction between users and the user interface. This makes your website more interactive which ultimately attracts more visitors to your webpage.
CSS animations is little tricky but not too tough to master. In this thread, we will try to gain some decent knowledge about it.
Animation is all about changing one style to another at certain intervals or times. For doing that, we need to learn about `@ keyframes` at rule
The keyframe provides us animation by changing the style sequentially according to the mentioned interval.
The keyframe provides us animation by changing the style sequentially according to the mentioned interval.
In order to bind the keyframe with a particular animation, we need to define few things like name and timing of animations.
We have several properties for that like animation-name, animation-timing, etc...
We have several properties for that like animation-name, animation-timing, etc...
Either we can use each property of animation or we can use animation shorthand property which includes:
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
animation-fill-mode
animation-play-state
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
animation-fill-mode
animation-play-state
Explanation:
Black box is going 500px from left boundary in 4 seconds because we have mentioned 4 seconds in animation property and 500px in keyframe at rule.
Black box is going 500px from left boundary in 4 seconds because we have mentioned 4 seconds in animation property and 500px in keyframe at rule.
You can also specify the delay in your animation using animation delay property.
It specifies a delay before the start of an animation
It specifies a delay before the start of an animation
So far so good, But we can also change the speed curve of animation and can create more smooth animation. And we have animation-timing-function property for that.
You can pass following values in animation-timing function
- ease (slow start, then fast, then slow)
- linear (same speed)
- ease-in (slow start)
- ease-out (slow end)
- ease-in-out (slow start and slow end)
- cubic-bezier (customizable)
- ease (slow start, then fast, then slow)
- linear (same speed)
- ease-in (slow start)
- ease-out (slow end)
- ease-in-out (slow start and slow end)
- cubic-bezier (customizable)
See this video for better understanding or you can play with code here
codepen.io
codepen.io
One thing to note here is that animation do not affect element before or after the keyframes.
In order to persist the styling based on last or first keyframe, we have animation-fill-mode
In order to persist the styling based on last or first keyframe, we have animation-fill-mode
It accepts following value
- forwards (element will retain last keyframe styling)
- backwards (element will get the first keyframe value even in animation-delay period)
- both (both of the above)
- forwards (element will retain last keyframe styling)
- backwards (element will get the first keyframe value even in animation-delay period)
- both (both of the above)
And that's it. I tried my best to give a quick overview of how CSS animations works
If you like this thread, drop a like and retweet, means a lot to me ❤️
Peace out 😉
If you like this thread, drop a like and retweet, means a lot to me ❤️
Peace out 😉
Loading suggestions...