当前位置:Gxlcms > JavaScript > cssanimation-direction属性怎么用

cssanimation-direction属性怎么用

时间:2021-07-01 10:21:17 帮助过:44人阅读

css animation-direction属性是用来定义是否应该轮流反向播放动画的;当动画播放次数超过一次时,我们就可以通过设置animation-direction的值为alternate来实现动画轮流反向播放。

css animation-direction属性怎么用?

animation-direction属性是用来定义是否应该轮流反向播放动画的;当动画播放次数超过一次时,我们就可以通过设置animation-direction的值为alternate来实现动画轮流反向播放。

作用:定义是否应该轮流反向播放动画。

语法:

  1. animation-direction: normal|alternate;

说明:normal 默认值。动画应该正常播放。alternate 动画应该轮流反向播放。

注释:如果把动画设置为只播放一次,则该属性没有效果。

css animation-direction属性使用示例

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. div
  6. {
  7. width:100px;
  8. height:100px;
  9. background:red;
  10. position:relative;
  11. animation:myfirst 5s infinite;
  12. animation-direction:alternate;
  13. /* Safari and Chrome */
  14. -webkit-animation:myfirst 5s infinite;
  15. -webkit-animation-direction:alternate;
  16. }
  17. @keyframes myfirst
  18. {
  19. 0% {background:red; left:0px; top:0px;}
  20. 25% {background:yellow; left:200px; top:0px;}
  21. 50% {background:blue; left:200px; top:200px;}
  22. 75% {background:green; left:0px; top:200px;}
  23. 100% {background:red; left:0px; top:0px;}
  24. }
  25. @-webkit-keyframes myfirst /* Safari and Chrome */
  26. {
  27. 0% {background:red; left:0px; top:0px;}
  28. 25% {background:yellow; left:200px; top:0px;}
  29. 50% {background:blue; left:200px; top:200px;}
  30. 75% {background:green; left:0px; top:200px;}
  31. 100% {background:red; left:0px; top:0px;}
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <p><strong>注释:</strong>Internet Explorer 9 以及更早的版本不支持 animation-direction 属性。</p>
  37. <div></div>
  38. </body>
  39. </html>

效果输出:

f5e1ca243adf2a77f58024fcdfed678.png

以上就是css animation-direction属性怎么用的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行