要应用animation动漫,先要熟习1下keyframes,Keyframes的英语的语法标准:取名是由”@keyframes”开始,后边紧接着是这个“动漫的名字”再加1对花括号“{}”,括号中便是1些不一样時间段款式标准。不一样重要帧是根据from(非常于0%)、to(非常于100%)或百分比来表明(以便获得最好的访问器适用,提议应用百分比),以下界定1个简易的动漫:
CSS Code拷贝內容到剪贴板
- @keyframes myfirst
- {
- 0% {background:red; left:0px; top:0px;}
- 25% {background:yellow; left:200px; top:0px;}
- 50% {background:blue; left:200px; top:200px;}
- 75% {background:green; left:0px; top:200px;}
- 100% {background:red; left:0px; top:0px;}
- }
-
@keyframes界定好了,要使其能充分发挥实际效果,务必根据animation把它关联到1个挑选器,不然动漫不容易有任何实际效果。下面列出了animation的特性:
下面设定上述的全部特性
CSS Code拷贝內容到剪贴板
- animation-name:myfirst;
- animation-duration:5s;
- animation-timing-function:linear;
- animation-delay:1s;
- animation-iteration-count:infinite;
- animation-direction:alternate;
- animation-play-state:running;
-
上述全部编码能够以下简写:
CSS Code拷贝內容到剪贴板
- animation:myfirst 5s linear 2s infinite alternate;
- animation-play-state:running;
-
访问器适配性
Internet Explorer 10、Firefox 和 Opera 适用 @keyframes 标准和 animation 特性。
Chrome 和 Safari 必须前缀 -webkit-。
留意:Internet Explorer 9,和更早的版本号,不适用 @keyframe 标准或 animation 特性。
下面得出上面详细介绍的有关keyframes和animation特性的详细编码示例:
XML/HTML Code拷贝內容到剪贴板
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF⑻">
- <title>animation演试</title>
- <style>
- div
- {
- width:100px;
- height:100px;
- background:red;
- position:relative;
- animation-name:myfirst;
- animation-duration:5s;
- animation-timing-function:linear;
- animation-delay:1s;
- animation-iteration-count:infinite;
- animation-direction:alternate;
- animation-play-state:running;
- /* Safari and Chrome: */
- -webkit-animation-name:myfirst;
- -webkit-animation-duration:5s;
- -webkit-animation-timing-function:linear;
- -webkit-animation-delay:1s;
- -webkit-animation-iteration-count:infinite;
- -webkit-animation-direction:alternate;
- -webkit-animation-play-state:running;
- }
-
- @keyframes myfirst /*界定动漫名*/
- {
- 0% {background:red; left:0px; top:0px;} /*界定起止帧款式,0%非常于from*/
- 25% {background:yellow; left:200px; top:0px;}
- 50% {background:blue; left:200px; top:200px;}
- 75% {background:green; left:0px; top:200px;}
- 100% {background:red; left:0px; top:0px;} /*界定完毕帧款式,100%非常于to*/
- }
-
- @-webkit-keyframes myfirst /* Safari and Chrome */
- {
- 0% {background:red; left:0px; top:0px;}
- 25% {background:yellow; left:200px; top:0px;}
- 50% {background:blue; left:200px; top:200px;}
- 75% {background:green; left:0px; top:200px;}
- 100% {background:red; left:0px; top:0px;}
- }
- </style>
- </head>
- <body>
- <p>该案例在 Internet Explorer 9 及更早 IE 版本号是失效的。</p>
- <div></div>
- </body>
- </html>
上面编码演试了1个正方形沿着1个正方形运动轨迹健身运动,基多次按正方位健身运动,偶多次按反向健身运动,健身运动全过程中还带有色调转变。实际实际效果,读者能够自主运作编码观查。
以上便是本文的所有內容,期待对大伙儿的学习培训有一定的协助,也期待大伙儿多多适用脚本制作之家。