6_动画.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. font-size: 100px;
  13. text-align: center;
  14. line-height: 200px;
  15. color: #fff;
  16. font-weight: bold;
  17. position: absolute;
  18. top:0;
  19. left:0;
  20. /* 动画 animation */
  21. /* animation 后面的参数为 动画名称 动画时间 动画曲线 动画延迟 动画次数 动画结束状态 (forwards 保持最后帧) */
  22. /* animation: move 1s linear 2s 2 forwards ; */
  23. /* 动画名称 用来定义动画关键帧(动画名称) */
  24. animation-name: move;
  25. /* 动画时间 用来定义动画的持续时间 */
  26. animation-duration: 1s;
  27. /* 动画曲线 用来定义动画的运动轨迹 */
  28. animation-timing-function: linear;
  29. /* 动画延迟 用来定义动画的延迟时间 */
  30. animation-delay: 2s;
  31. /* 动画次数 用来定义动画的次数 infinite 无限循环 */
  32. animation-iteration-count: infinite;
  33. /* 动画结束状态 用来定义动画的结束状态 */
  34. animation-fill-mode: forwards;
  35. }
  36. /* @keyframes 用来定义动画关键帧(动画名称) */
  37. /* 这里动画名称可以任意起名字 */
  38. /* 动画关键帧 用来定义动画的运动轨迹 */
  39. /* 这里from和to是开始和结束 */
  40. @keyframes move{
  41. /* from{
  42. left:0;
  43. }
  44. to{
  45. left:200px;
  46. } */
  47. 0%{
  48. left:0;
  49. }
  50. 50%{
  51. left:100px;
  52. }
  53. 100%{
  54. top:100px;
  55. background-color: blue;
  56. }
  57. }
  58. .box:hover{
  59. animation-play-state: paused;
  60. }
  61. </style>
  62. </head>
  63. <body>
  64. <div class="box">
  65. </div>
  66. </body>
  67. </html>