CSS3 animation - animation properties
The CSS3 animation animation property is a standard property used by CSS to design webpage animations. CSS3 animation has many different properties and effects that can be set to control the animation movement, movement direction, color change... and other effects, which are very powerful. , CSS3 animation property can even achieve traditional animation effects that need to be designed with JavaScript or Flash. The advantage is that less complex animations can be designed without JavaScript at all, and it has the advantage of consuming resources. If you want to use JavaScript to design the same effect Animations usually require more complex code and consume more resources. CSS3 animation delegates the animation generation to the browser, which is also helpful for animation optimization.
To use the animation properties, you only need to set the properties of the animation and the keyframes to make the animation run easily, but the support level of each browser is not consistent, so in the CSS syntax, you will need to add a special browser The written prefix (prefix), this part will be seen in the example.
Basic setting 1: CSS3 animation animation property syntax
CSS3 animation animation property list
Attributes | Description |
animation-name | Define the keyframes @keyframes name of the animation. |
animation-duration | Define the time for the animation to execute once, in seconds or milliseconds. |
animation-timing-function | Define the speed curve of the animation execution, such as linear linear or low speed start. |
animation-delay | Define the time from the completion of the animation preparation to the start of the action. The unit can be seconds. If it is 0s, it means no delay. |
animation-iteration-count | Define the number of times the animation is executed repeatedly. If you want to execute infinitely, you can use infinite. |
animation-direction | Define whether the animation needs to be executed in the reverse direction after one time. If you want to execute the animation in reverse, you can use alternate. |
keyframe settings The keyframes setting can be said to be the key to the CSS3 animation effect. If the keyframe settings are missing, the animation will not run. There are two important points to set the keyframes. They are: Where to start (from) and where to end (to), the key frame is to judge the start time and end time of the animation through percentage, 0% represents the start point of the animation, and 100% represents the end point of the animation , Use from and to to set, this part will also be seen in the example. The key frame describes the appearance of the animation creation process, that is to say, in addition to using the key frame to control the running of the animation, you can also control the color change of the animation.
CSS3 animation example 1: Move the DIV block from left to right
<!--
#D1{
width:100px;
height:100px;
background:red;
position:relative;
animation:TestMove 5s infinite; /*IE*/
-moz-animation:TestMove 5s infinite; /*FireFox*/
-webkit-animation:TestMove 5s infinite; /*Chrome, Safari*/
}
@keyframes TestMove{
from {left:0%;}
to {left:80%;}
}
@-moz- keyframes TestMove{
from {left:0%;}
to {left:80%;}
}
@-webkit-keyframes TestMove{
from {left:0%;}
to {left:80%;}
}
-->
</style >
<div style="width:700px;border:1px #ccc solid;padding:20px;">
<div id="D1"></div>
</div>
In the example, the animation attribute and the keyframes are prefixed with prefixes. This function is to allow different browsers to support the animation effect. Among them, "-moz-" is for FireFox to support, "-webkit -" is to allow Chrome and Safari to support, neither prefix is shown for IE, IE10 began to support CSS3 animation properties, IE9 and earlier versions of IE browsers do not support animation effects.
CSS3 animation example 2: Let the DIV block move back and forth
<!--
#D2{
width:100px;
height:100px;
background:red;
position:relative;
animation:TestMove2 5s infinite alternate; /*IE*/
-moz-animation: TestMove2 5s infinite alternate; /*FireFox*/
-webkit-animation:TestMove2 5s infinite alternate; /*Chrome, Safari*/
}
@keyframes TestMove2{
from {left:0%;}
to {left:80%;}
}
@ -moz-keyframes TestMove2{
from {left:0%;}
to {left:80%;}
}
@-webkit-keyframes TestMove2{
from {left:0%;}
to {left:80%;}
}
-->
</style>
<div style="width:700px;border:1px #ccc solid;padding:20px;">
<div id="D2"></div>
</div>
CSS3 animation example 3: Let the DIV block change color
<!--
#D3{
width:200px;
height:100px;
background:red;
position:relative;
animation:TestMove3 3s infinite alternate; /*IE*/
-moz-animation: TestMove3 3s infinite alternate; /*FireFox*/
-webkit-animation:TestMove3 3s infinite alternate; /*Chrome, Safari*/
}
@keyframes TestMove3{
from {background-color:red;}
to {background-color:orange;}
}
@-moz-keyframes TestMove3{
from {background-color:red;}
to {background-color:orange;}
}
@-webkit-keyframes TestMove3{
from {background-color:red;}
to {background-color:orange ;}
}
-->
</style>
<div style="width:700px;border:0px #ccc solid;padding:20px;">
<div id="D3"></div>
</div>
- The syntax "from {background-color:red;}" sets the block background color to red
- The syntax "from {background-color:orange;}" sets the block background color to orange
Post a Comment
0 Comments