The grammar of a animation
1, @keyframes--insert KeyFrames
(1) Formto form:
CSS code copy content to clipboard
@keyframes Demo {
from {
Properties:properties value;
}
Percentage {
Properties:properties value;
}
to {
Properties:properties value;
}
}
(2) The form of a percentage:
CSS code copy content to clipboard
@keyframes Demo {
0% {
Properties:properties value;
}
Percentage {
Properties:properties value;
}
100% {
Properties:properties value;
}
}
2, animation-name--define the name of the animation
Animation-name:none | "Name of the animation";
(1) The name of the animation is the animated name created by KeyFrames, which must be consistent with the animated name created. If inconsistent, you will not be able to achieve any animation effects
(2) None is the default, and none is on, there will be no animation effect
3, Animation-duration
Animation-duration:time (s)
Animation-duration is the duration of the specified element to play the animation, with a value of seconds (s) and a default value of "0".
4, Animation-timing-function
Animation-timing-function:ease (buffer) | | Ease-in (accelerated) | | Ease-out (deceleration) | | Ease-in-out (acceleration and deceleration) | | Linear (uniform) | | Cubic-bezier (Customize a Time curve)
Animation-timing-function is used to specify how the animation is played, with the following six modes of transformation: ease (buffering), ease-in (acceleration), ease-out (deceleration), ease-in-out (acceleration and deceleration); Linear ( uniform); Cubic-bezier (custom a time curve).
5, Animation-delay
Animation-delay:time (s)
Animation-delay: is used to specify the element animation start time. Values are numeric, in seconds (s), and the default value is "0". This property is the same as the Animation-duration use method.
6, Animation-iteration-count
Animation-iteration-count:infinite | | Number
Animation-iteration-count is the number of times the specified element plays the animation, the value is a number, the default value is "1" or infinite (infinite number of loops).
7, Animation-direction
Animation-direction:normal | | Alternate
Animation-direction is the direction of the specified element animation, if normal, then each cycle of the animation is played forward, if it is alternate, then the animation playback in the number of times forward, the odd number of times to play in the opposite direction.
8, Animation-play-state
animation-play-state:running | | Paused
Animation-play-state is mainly used to control the playback state of element animations. It has two main values, running and paused, where running is the default value. This property currently has very little kernel support, so just a little mention.
Second, animation event interface
In fact, at present the basic is three events only: Start, iteration, end. The beginning and the end know what it means. As for this iteration, because there is a Iteration-count attribute in animation, it can define the number of times the animation repeats, so there are many times when the animation starts and ends. But the real "start" and "End" events are about the entire animation, they only trigger once, and the "End and start the next time" caused by repeated animations will trigger the entire "Iteration" event.
The standard names for these three events are:
Start: Animationstart
Iteration: Animationiteration
End: Animationend
But the current version of Chrome needs to be prefixed with the WebKit, and also to be careful of case
Start: Webkitanimationstart
Iteration: Webkitanimationiteration
End: Webkitanimationend
Finally, the example code and screenshot
CSS Code copy content to clipboard
- <style>
- @-webkit-keyframes Test {
- 0% {background:red;}
- 25% {background:green;}
- 50% {background:blue;}
- 100% {background:red;}
- }
- @keyframes Test {
- 0% {background:red;}
- 25% {background:green;}
- 50% {background:blue;}
- 100% {background:red;}
- }
- </style>
- <script>
- Onload=function () {
- var html=document.documentelement;
- Defining an event callback function
- var start=function () {
- Console.log ("Start");
- },iteration=function (e) {
- Console.log (e);
- },end=function () {
- Console.log ("End");
- };
- Binding events
- Html.addeventlistener ("webkitanimationiteration", iteration);
- Html.addeventlistener ("animationiteration", iteration);
- Html.addeventlistener ("Webkitanimationstart", start);
- Html.addeventlistener ("Animationstart", start);
- Html.addeventlistener ("Webkitanimationend", end);
- Html.addeventlistener ("Animationend", end);
- Start animation
- html.style.animation=
- html.style.webkitanimation=
- "test 1s linear 0s 3";
- };
- </script