CSS3 animation properties

CSS3 new animation attribute"@keyframes", you can see its meaning literally - keyframe, which is consistent with the meaning in Flash. The principle of using CSS3 to create animation effects is the same as Flash. We need to define the state effects at key frames and use CSS3 to drive the animation effects.

Syntax

##@keyframes animationname {keyframes-selector {css-styles;}}animationname required. Defines the name of the animation.
keyframes-selector
Required. The percentage of animation duration.
Legal values:
0-100%
from (same as 0%)
to (same as 100%)
css-styles Required. One or more legal CSS style properties.

Definition and UsageWith @keyframes rules, you can create animations.
The principle of creating animation is to gradually change one set of CSS styles into another set of styles.
You can change this set of CSS styles multiple times during the animation.
Specify the time when the change occurs as a percentage, or through the keywords "from" and "to", which are equivalent to 0% and 100%.
0% is the start time of the animation, 100% is the end time of the animation.
For best browser support, you should always define 0% and 100% selectors.
Note: Please use animation properties to control the appearance of the animation and bind the animation to the selector.

Browser support

Currently, browsers do not support @keyframes rules.

Firefox supports alternative @-moz-keyframes rules.
Opera supports alternative @-o-keyframes rules.
Safari and Chrome support alternative @-webkit-keyframes rules.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
    <style type="text/css">
        div {
            width: 100px;
            height: 100px;
            background: #ff72cc;
            position: relative;
            animation: mymove 5s infinite;
            -moz-animation: mymove 5s infinite; /* Firefox */
            -webkit-animation: mymove 5s infinite; /* Safari and Chrome */
            -o-animation: mymove 5s infinite; /* Opera */
        }
        @keyframes mymove {
            0% {
                top: 0px;
            }
            25% {
                top: 200px;
            }
            75% {
                top: 50px
            }
            100% {
                top: 100px;
            }
        }
        @-moz-keyframes mymove /* Firefox */
        {
            0% {
                top: 0px;
            }
            25% {
                top: 200px;
            }
            75% {
                top: 50px
            }
            100% {
                top: 100px;
            }
        }
        @-webkit-keyframes mymove /* Safari and Chrome */
        {
            0% {
                top: 0px;
            }
            25% {
                top: 200px;
            }
            75% {
                top: 50px
            }
            100% {
                top: 100px;
            }
        }
        @-o-keyframes mymove /* Opera */
        {
            0% {
                top: 0px;
            }
            25% {
                top: 200px;
            }
            75% {
                top: 50px
            }
            100% {
                top: 100px;
            }
        }
    </style>
</head>
<body>
<div></div>
</body>
</html>

CSS3 Animations

When creating animations in @keyframes, bind it to a selector, otherwise the animation will have no effect.

Specify that at least two CSS3 animation properties are bound to a selector:

Specify the name of the animation

Specify the duration of the animation

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
    <style type="text/css">
            div {
            width: 100px;
            height: 100px;
            background: red;
            position: relative;
            animation: mymove 5s infinite;
            -moz-animation: mymove 5s infinite; /* Firefox */
            -webkit-animation: mymove 5s infinite; /* Safari and Chrome */
            -o-animation: mymove 5s infinite; /* Opera */
        }
        @keyframes mymove {
            0% {
                top: 0px;
                background: red;
                width: 100px;
            }
            100% {
                top: 200px;
                background: yellow;
                width: 300px;
            }
        }
        @-moz-keyframes mymove /* Firefox */
        {
            0% {
                top: 0px;
                background: red;
                width: 100px;
            }
            100% {
                top: 200px;
                background: yellow;
                width: 300px;
            }
        }
        @-webkit-keyframes mymove /* Safari and Chrome */
        {
            0% {
                top: 0px;
                background: red;
                width: 100px;
            }
            100% {
                top: 200px;
                background: yellow;
                width: 300px;
            }
        }
        @-o-keyframes mymove /* Opera */
        {
            0% {
                top: 0px;
                background: red;
                width: 100px;
            }
            100% {
                top: 200px;
                background: yellow;
                width: 300px;
            }
        }
    </style>
</head>
<body>
  <p><b>注释:</b>本例在 Internet Explorer 中无效。</p>
  <div></div>
</body>
</html>

CSS3 Animation properties

The following table lists the @keyframes rules and all animation properties:

Properties               Description             CSS

@keyframes Specifies animation. 3  

animation Shorthand property for all animation properties, except animation-play-state property. 3  

animation-name Specifies the name of @keyframes animation. 3

animation-duration Specifies the seconds or milliseconds it takes for the animation to complete one cycle. The default is 0. 3  

animation-timing-function   Specifies the speed curve of animation. The default is "ease". 3  

animation-delay Specifies when the animation starts. 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 will play in reverse in the next cycle. The default is "normal". 3

animation-play-state Specifies whether the animation is running or paused. The default is "running". 3

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
    <style type="text/css">
        div {
            width: 100px;
            height: 100px;
            background: red;
            position: relative;
            animation: mymove 5s infinite;
            -moz-animation: mymove 5s infinite; /* Firefox */
            -webkit-animation: mymove 5s infinite; /* Safari and Chrome */
            -o-animation: mymove 5s infinite; /* Opera */
           }
        @keyframes mymove {
            0% {
                top: 0px;
                left: 0px;
                background: red;
            }
            25% {
                top: 0px;
                left: 100px;
                background: blue;
            }
            50% {
                top: 100px;
                left: 100px;
                background: yellow;
            }
            75% {
                top: 100px;
                left: 0px;
                background: green;
            }
            100% {
                top: 0px;
                left: 0px;
                background: red;
            }
        }
        @-moz-keyframes mymove /* Firefox */
        {
            0% {
                top: 0px;
                left: 0px;
                background: red;
            }
            25% {
                top: 0px;
                left: 100px;
                background: blue;
            }
            50% {
                top: 100px;
                left: 100px;
                background: yellow;
            }
            75% {
                top: 100px;
                left: 0px;
                background: green;
            }
            100% {
                top: 0px;
                left: 0px;
                background: red;
            }
        }
        @-webkit-keyframes mymove /* Safari and Chrome */
        {
            0% {
                top: 0px;
                left: 0px;
                background: red;
            }
            25% {
                top: 0px;
                left: 100px;
                background: blue;
            }
            50% {
                top: 100px;
                left: 100px;
                background: yellow;
            }
            75% {
                top: 100px;
                left: 0px;
                background: green;
            }
            100% {
                top: 0px;
                left: 0px;
                background: red;
            }
        }  
        @-o-keyframes mymove /* Opera */
        {
            0% {
                top: 0px;
                left: 0px;
                background: red;
            }
            25% {
                top: 0px;
                left: 100px;
                background: blue;
            }
            50% {
                top: 100px;
                left: 100px;
                background: yellow;
            }
            75% {
                top: 100px;
                left: 0px;
                background: green;
            }
            100% {
                top: 0px;
                left: 0px;
                background: red;
            }
        }
    </style>
</head>
<body>
  <p><b>注释:</b>本例在 Internet Explorer 中无效。</p>
  <div></div>
</body>
</html>


Continuing Learning
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> <style type="text/css"> div { width: 100px; height: 100px; background: red; position: relative; animation: mymove 5s infinite; -moz-animation: mymove 5s infinite; /* Firefox */ -webkit-animation: mymove 5s infinite; /* Safari and Chrome */ -o-animation: mymove 5s infinite; /* Opera */ } @keyframes mymove { 0% { top: 0px; background: red; width: 100px; } 100% { top: 200px; background: yellow; width: 300px; } } @-moz-keyframes mymove /* Firefox */ { 0% { top: 0px; background: red; width: 100px; } 100% { top: 200px; background: yellow; width: 300px; } } @-webkit-keyframes mymove /* Safari and Chrome */ { 0% { top: 0px; background: red; width: 100px; } 100% { top: 200px; background: yellow; width: 300px; } } @-o-keyframes mymove /* Opera */ { 0% { top: 0px; background: red; width: 100px; } 100% { top: 200px; background: yellow; width: 300px; } } </style> </head> <body> <p><b>注释:</b>本例在 Internet Explorer 中无效。</p> <div></div> </body> </html>
submitReset Code