03.动画.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. *{
  10. margin: 0;
  11. padding: 0;
  12. }
  13. .box1{
  14. width: 800px;
  15. height: 800px;
  16. background-color: silver;
  17. overflow: hidden;
  18. margin-left: 0;
  19. }
  20. .box1 div{
  21. width: 100px;
  22. height: 100px;
  23. margin-bottom: 100px;
  24. margin-left: 10px;
  25. }
  26. .box2{
  27. background-color: #bfa;
  28. /* 设置box2的动画 */
  29. /* animation-name:要对当前元素生效的关键帧的名字 */
  30. /* animation-name: test; */
  31. /* animation-duration:动画的执行时间 */
  32. /* animation-duration: 2s; */
  33. /* animation-delay:动画的延时 */
  34. /* animation-delay: 2s; */
  35. /* animation-timing-function: ease-in-out; */
  36. /*
  37. animation-iteration-count:动画执行的次数
  38. 可选值:
  39. 次数
  40. infinite 无限执行
  41. */
  42. /* animation-iteration-count: 2; */
  43. /*
  44. animation-direction:指定动画运行的方向
  45. 可选值:
  46. normal:默认值,从from向to,每次都是这样
  47. reverse:从to向from运行,每次都是这样
  48. alternate:从from向to,重复执行动画时反向执行
  49. alternate-reverse:从to向from运行,重复执行动画时反向执行
  50. */
  51. /* animation-direction: normal;
  52. animation-direction: reverse;
  53. animation-direction: alternate;
  54. animation-direction: alternate-reverse; */
  55. /*
  56. animation-play-state:设置动画的执行状态
  57. 可选值:
  58. running:默认值,动画执行
  59. paused:动画暂停
  60. */
  61. /* animation-play-state: paused; */
  62. /*
  63. animation-fill-mode:动画的填充模式
  64. 可选值:
  65. none:默认值,动画执行完毕,元素回到原来的位置
  66. forwards:动画执行完毕,元素会停止在动画结束的位置
  67. backwards:动画延时等待时,元素就会处于开始位置
  68. both:结合了forwards和backwards
  69. */
  70. /* animation-fill-mode:both; */
  71. /*
  72. animation:简写属性,第一个时间表示动画的持续时间,第二个时间表示延迟时间,
  73. 其他没有顺序要求
  74. */
  75. animation: test 2s 3 1s alternate;
  76. }
  77. /* .box1:hover div{
  78. animation-play-state: paused
  79. } */
  80. /*
  81. 动画
  82. 动画和过渡类似,都是可以实现一些动态的效果,
  83. 不同的是过渡需要在某个属性发生变化时才会触发
  84. 动画可以自动触发动态效果
  85. 设置动画效果,必须先要设置一个关键帧,关键帧设置了动画执行的每一个步骤
  86. */
  87. @keyframes test{
  88. /* from 表示动画的开始位置,也可以使用0% */
  89. from{
  90. margin-left: 0;
  91. background-color: orange;
  92. }
  93. /* to 表示动画的结束位置,也可以使用100% */
  94. to{
  95. margin-left: 700px;
  96. background-color: red;
  97. }
  98. }
  99. </style>
  100. </head>
  101. <body>
  102. <div class="box1">
  103. <div class="box2"></div>
  104. <!-- <div class="box3"></div> -->
  105. </div>
  106. </body>
  107. </html>