6_动画.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. .box{
  9. width: 200px;
  10. height: 200px;
  11. background-color: red;
  12. margin:100px auto;
  13. /* animation 定义动画 */
  14. /* 第一个参数为动画名称 第二个参数持续的时间 第三个参数动画效果 */
  15. /* 动画默认情况下结束后会返回初始状态 */
  16. /* 如果添加第四个值为forwards 停在结束状态 */
  17. /* 第五参数为动画需要执行的次数 infinite 表示无限执行*/
  18. /* animation: foo 1s linear forwards infinite; */
  19. /* animation-name 动画名称 */
  20. animation-name: foo;
  21. /* animation-duration 持续时间 */
  22. animation-duration: 1s;
  23. /* animation-timing-function 动画效果 */
  24. animation-timing-function: linear;
  25. /* animation-fill-mode 动画结束时的状态 */
  26. animation-fill-mode: forwards;
  27. /* animation-iteration-count 动画执行的次数 */
  28. animation-iteration-count: 2;
  29. /* animation-delay 动画延时 */
  30. animation-delay: 1s;
  31. }
  32. .box:hover{
  33. /* animation-play-state:paused 控制动画暂停 */
  34. animation-play-state: paused;
  35. }
  36. /* keyframes 定义动画关键帧 后面为定义的名称 */
  37. /* from 从什么状态开始 to 到什么样状态 */
  38. @keyframes foo{
  39. /* from{
  40. width: 200px;
  41. }
  42. to{
  43. width: 400px;
  44. } */
  45. 0%{
  46. width: 200px;
  47. height: 200px;
  48. }
  49. 50%{
  50. width: 600px;
  51. height: 200px;
  52. }
  53. 100%{
  54. width: 400px;
  55. height: 400px;
  56. }
  57. }
  58. </style>
  59. </head>
  60. <body>
  61. <div class="box"></div>
  62. </body>
  63. </html>