May 04, 2021 CSS3
CSS3, we can create animations, which can replace many web animation images, Flash animations, and JAVAScripts.
The numbers in the table support the first browser version number of the property.
@keyframes rule is to create an animation. @keyframes A CSS style and animation within the rules will gradually change from the current style to the new style.
Internet Explorer 10, Firefox, and Opera support @keyframes rules and animation properties.
The number immediately before -webkit-, -ms- or -moz- is the first browser version number that supports the prefix property.
Attributes | |||||
---|---|---|---|---|---|
@keyframes |
43.0
4.0 -webkit- |
10.0 |
16.0
5.0 -moz- |
9.0
4.0 -webkit- |
30.0
15.0 -webkit- 12.0 -o- |
animation |
43.0
4.0 -webkit- |
10.0 |
16.0
5.0 -moz- |
9.0
4.0 -webkit- |
30.0
15.0 -webkit- 12.0 -o- |
When you @keyframe an animation, bind it to a selector, otherwise the animation will have no effect.
Specify that at least two of these CSS3 animation properties are bound to one selector:
Specify the name of the animation
Specify the length of the animation
Bundle the "myfirst" animation into the div element for 5 seconds:
Note: You must define the name of the animation and the duration of the animation. If you omit the duration, the animation will not run because the default value is 0.
Animation is the effect of gradually changing an element from one style to another.
You can change as many styles as you want.
Use a percentage to specify when the change occurred, or use the keywords "from" and "to" equivalent to 0% and 100%.
0% is the beginning of the animation and 100% is the completion of the animation.
For optimal browser support, you should always define 0% and 100% selectors.
Change the background color when the animation is 25% and 50%, and then change again when the animation is 100% complete:
Change the background color and position:
The following table lists @keyframes rules and all animation properties:
Property | Describe | Css |
---|---|---|
@keyframes | Specified animation. | 3 |
animation | Short-case properties for all animation properties, except the animation-play-state property. | 3 |
animation-name | Specifies the @keyframes of the animation. | 3 |
animation-duration | Specifies the number of seconds or milliseconds it takes for the animation to complete a cycle. The default is 0. | 3 |
animation-timing-function | Specifies the speed curve of the animation. The default is "ease". | 3 |
animation-delay | Specify when the animation will start. The default is 0. | 3 |
animation-iteration-count | Specifies the number of times the animation is played. The default is 1. | 3 |
animation-direction | Specifies whether the animation plays in reverse in the next cycle. The default is "normal". | 3 |
animation-play-state | Specifies whether the animation is running or pausing. The default is "running." | 3 |
Here are two examples of setting all animation properties:
Run the myfirst animation and set all the properties:
Same as the animation above, but using the short animation animation property:
The above two examples set all the animation properties, you'd better look at them a few times and do it yourself!