当前位置:   article > 正文

css动画演示_css 动画演示

css 动画演示

动画1(沿着椭圆转动)

 其实是个2D转动,只不过咱们设置椭圆,然后加上scale缩放(近大远小),看上去就是3D效果

  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>动画1</title>
  8. </head>
  9. <body>
  10. <style>
  11. * {
  12. margin: 0;
  13. padding: 0;
  14. box-sizing: border-box;
  15. }
  16. body {
  17. width: 100vw;
  18. height: 100vh;
  19. position: relative;
  20. }
  21. /* 位置 */
  22. .container {
  23. position: absolute;
  24. width: 800px;
  25. height: 180px;
  26. top: 20%;
  27. left: 50%;
  28. transform: translateX(-60%);
  29. /* border: 1px solid red; */
  30. }
  31. /* 动画的容器(椭圆) */
  32. .box {
  33. width: 100%;
  34. height: 100%;
  35. position: relative;
  36. /* border: 1px solid blue; */
  37. box-sizing: border-box;
  38. border-radius: 50%;
  39. }
  40. /* 椭圆线 */
  41. .border {
  42. position: absolute;
  43. width: 800px;
  44. height: 180px;
  45. top: 65px;
  46. left: 60px;
  47. border: 1px solid #0084ff;
  48. box-sizing: border-box;
  49. border-radius: 50%;
  50. }
  51. /* 以下是转动的动画 */
  52. .circle {
  53. width: 200px;
  54. height: 130px;
  55. position: absolute;
  56. z-index: 999;
  57. }
  58. .circle img {
  59. width: 100%;
  60. height: 100%;
  61. }
  62. .circle1 {
  63. animation: animX 11s cubic-bezier(0.36, 0, 0.64, 1) -5.5s infinite alternate,
  64. animY 11s cubic-bezier(0.36, 0, 0.64, 1) 0s infinite alternate,
  65. scale 22s cubic-bezier(0.36, 0, 0.64, 1) 0s infinite alternate;
  66. }
  67. .circle2 {
  68. animation: animX 11s cubic-bezier(0.36, 0, 0.64, 1) -7.5s infinite alternate,
  69. animY 11s cubic-bezier(0.36, 0, 0.64, 1) -2s infinite alternate,
  70. scale 22s cubic-bezier(0.36, 0, 0.64, 1) -2s infinite alternate;
  71. }
  72. .circle3 {
  73. animation: animX 11s cubic-bezier(0.36, 0, 0.64, 1) -9.5s infinite alternate,
  74. animY 11s cubic-bezier(0.36, 0, 0.64, 1) -4s infinite alternate,
  75. scale 22s cubic-bezier(0.36, 0, 0.64, 1) -4s infinite alternate;
  76. }
  77. .circle4 {
  78. animation: animX 11s cubic-bezier(0.36, 0, 0.64, 1) -11.5s infinite alternate,
  79. animY 11s cubic-bezier(0.36, 0, 0.64, 1) -6s infinite alternate,
  80. scale 22s cubic-bezier(0.36, 0, 0.64, 1) -6s infinite alternate;
  81. }
  82. .circle5 {
  83. animation: animX 11s cubic-bezier(0.36, 0, 0.64, 1) -13.5s infinite alternate,
  84. animY 11s cubic-bezier(0.36, 0, 0.64, 1) -8s infinite alternate,
  85. scale 22s cubic-bezier(0.36, 0, 0.64, 1) -8s infinite alternate;
  86. }
  87. .circle6 {
  88. animation: animX 11s cubic-bezier(0.36, 0, 0.64, 1) -15.5s infinite alternate,
  89. animY 11s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate,
  90. scale 22s cubic-bezier(0.36, 0, 0.64, 1) -10s infinite alternate;
  91. }
  92. .circle7 {
  93. animation: animX 11s cubic-bezier(0.36, 0, 0.64, 1) -17.5s infinite alternate,
  94. animY 11s cubic-bezier(0.36, 0, 0.64, 1) -12s infinite alternate,
  95. scale 22s cubic-bezier(0.36, 0, 0.64, 1) -12s infinite alternate;
  96. }
  97. .circle8 {
  98. animation: animX 11s cubic-bezier(0.36, 0, 0.64, 1) -19.5s infinite alternate,
  99. animY 11s cubic-bezier(0.36, 0, 0.64, 1) -14s infinite alternate,
  100. scale 22s cubic-bezier(0.36, 0, 0.64, 1) -14s infinite alternate;
  101. }
  102. .circle9 {
  103. animation: animX 11s cubic-bezier(0.36, 0, 0.64, 1) -21.5s infinite alternate,
  104. animY 11s cubic-bezier(0.36, 0, 0.64, 1) -16s infinite alternate,
  105. scale 22s cubic-bezier(0.36, 0, 0.64, 1) -16s infinite alternate;
  106. }
  107. .circle10 {
  108. animation: animX 11s cubic-bezier(0.36, 0, 0.64, 1) -23.5s infinite alternate,
  109. animY 11s cubic-bezier(0.36, 0, 0.64, 1) -18s infinite alternate,
  110. scale 22s cubic-bezier(0.36, 0, 0.64, 1) -18s infinite alternate;
  111. }
  112. .circle11 {
  113. animation: animX 11s cubic-bezier(0.36, 0, 0.64, 1) -25.5s infinite alternate,
  114. animY 11s cubic-bezier(0.36, 0, 0.64, 1) -20s infinite alternate,
  115. scale 22s cubic-bezier(0.36, 0, 0.64, 1) -20s infinite alternate;
  116. }
  117. @keyframes animX {
  118. 0% {
  119. left: -4%;
  120. }
  121. 100% {
  122. left: 96%;
  123. }
  124. }
  125. @keyframes animY {
  126. 0% {
  127. top: -4%;
  128. }
  129. 100% {
  130. top: 96%;
  131. }
  132. }
  133. @keyframes scale {
  134. 0% {
  135. transform: scale(0.4);
  136. opacity: 0.5;
  137. }
  138. 50% {
  139. transform: scale(1);
  140. opacity: 1;
  141. }
  142. 100% {
  143. transform: scale(0.4);
  144. opacity: 0.5;
  145. }
  146. }
  147. </style>
  148. <div class="container">
  149. <div class="box">
  150. <div class="circle circle1">
  151. <img src="./img/步数.png" alt="">
  152. </div>
  153. <div class="circle circle2">
  154. <img src="./img/胆固醇.png" alt="">
  155. </div>
  156. <div class="circle circle3">
  157. <img src="./img/肺呼吸.png" alt="">
  158. </div>
  159. <div class="circle circle4">
  160. <img src="./img/尿酸.png" alt="">
  161. </div>
  162. <div class="circle circle5">
  163. <img src="./img/睡眠.png" alt="">
  164. </div>
  165. <div class="circle circle6">
  166. <img src="./img/体脂.png" alt="">
  167. </div>
  168. <div class="circle circle7">
  169. <img src="./img/跳绳.png" alt="">
  170. </div>
  171. <div class="circle circle8">
  172. <img src="./img/握力.png" alt="">
  173. </div>
  174. <div class="circle circle9">
  175. <img src="./img/心率.png" alt="">
  176. </div>
  177. <div class="circle circle10">
  178. <img src="./img/血糖.png" alt="">
  179. </div>
  180. <div class="circle circle11">
  181. <img src="./img/血氧.png" alt="">
  182. </div>
  183. <!-- 椭圆线 -->
  184. <div class="border"></div>
  185. </div>
  186. </div>
  187. </body>
  188. </html>

1. scale去设置的总时间(也就是转一圈用的时间), 这里设置 22秒

2. X轴和Y轴用的时间是一样的,都为总时间的一半,也就是11秒

3. 相差的时间是 总时间/图片的个数  这里也就是 22/11 = 2秒

4.  X轴和Y轴的延时时间相差 11/2 = 5.5秒


可以把代码拷贝过去,修改一下试试就可以啦 

动画2 (旋转木马特效)

  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>动画2</title>
  8. </head>
  9. <body>
  10. <style>
  11. * {
  12. margin: 0;
  13. padding: 0;
  14. box-sizing: border-box;
  15. }
  16. body {
  17. width: 100vw;
  18. height: 100vh;
  19. position: relative;
  20. }
  21. .container {
  22. position: absolute;
  23. width: 1000px;
  24. height: 500px;
  25. top: 15%;
  26. left: 50%;
  27. transform: translateX(-50%);
  28. z-index: 999;
  29. display: flex;
  30. justify-content: center;
  31. align-items: center;
  32. perspective: 1000px;
  33. }
  34. .box {
  35. width: 150px;
  36. height: 150px;
  37. position: relative;
  38. transform-style: preserve-3d;
  39. animation: run 11s linear infinite;
  40. }
  41. .circle {
  42. position: absolute;
  43. top: 0;
  44. left: 0;
  45. width: 150px;
  46. height: 150px;
  47. }
  48. /*设置图像大小、边框、圆角、位置*/
  49. .circle img {
  50. width: 150px;
  51. height: 200px;
  52. border: 1px solid #ccc;
  53. border-radius: 5px;
  54. box-sizing: border-box;
  55. }
  56. .circle1 {
  57. transform: translateZ(500px);
  58. }
  59. .circle2 {
  60. transform: rotateY(36deg) translateZ(500px);
  61. }
  62. .circle3 {
  63. transform: rotateY(72deg) translateZ(500px);
  64. }
  65. .circle4 {
  66. transform: rotateY(108deg) translateZ(500px);
  67. }
  68. .circle5 {
  69. transform: rotateY(144deg) translateZ(500px);
  70. }
  71. .circle6 {
  72. transform: rotateY(180deg) translateZ(500px) ;
  73. }
  74. .circle7 {
  75. transform: rotateY(216deg) translateZ(500px);
  76. }
  77. .circle8 {
  78. transform: rotateY(252deg) translateZ(500px);
  79. }
  80. .circle9 {
  81. transform: rotateY(288deg) translateZ(500px);
  82. }
  83. .circle10 {
  84. transform: rotateY(324deg) translateZ(500px);
  85. }
  86. @keyframes run {
  87. 0% {
  88. transform: rotateY(0);
  89. }
  90. 100% {
  91. transform: rotateY(360deg);
  92. }
  93. }
  94. </style>
  95. <div class="container">
  96. <div class="box">
  97. <div class="circle circle1">
  98. <img src="./img/1.jpg" alt="">
  99. </div>
  100. <div class="circle circle2">
  101. <img src="./img/2.jpg" alt="">
  102. </div>
  103. <div class="circle circle3">
  104. <img src="./img/3.jpg" alt="">
  105. </div>
  106. <div class="circle circle4">
  107. <img src="./img/4.jpg" alt="">
  108. </div>
  109. <div class="circle circle5">
  110. <img src="./img/5.jpg" alt="">
  111. </div>
  112. <div class="circle circle6">
  113. <img src="./img/6.jpg" alt="">
  114. </div>
  115. <div class="circle circle7">
  116. <img src="./img/7.jpg" alt="">
  117. </div>
  118. <div class="circle circle8">
  119. <img src="./img/8.jpg" alt="">
  120. </div>
  121. <div class="circle circle9">
  122. <img src="./img/9.jpg" alt="">
  123. </div>
  124. <div class="circle circle10">
  125. <img src="./img/10.jpg" alt="">
  126. </div>
  127. </div>
  128. </div>
  129. </body>
  130. </html>

动画3 (沿X、Y、Z轴自转)

  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>动画3</title>
  8. </head>
  9. <body>
  10. <style>
  11. * {
  12. padding: 0;
  13. margin: 0;
  14. box-sizing: border-box;
  15. }
  16. body {
  17. width: 100vw;
  18. height: 100vh;
  19. display: flex;
  20. justify-content: center;
  21. align-items: center;
  22. }
  23. .container img {
  24. width: 150px;
  25. height: 150px;
  26. margin: 0 20px;
  27. }
  28. .container > img:nth-of-type(1) {
  29. animation: rotate1 5s linear infinite;
  30. }
  31. .container > img:nth-of-type(2) {
  32. animation: rotate2 5s linear infinite;
  33. }
  34. .container > img:nth-of-type(3) {
  35. animation: rotate3 5s linear infinite;
  36. }
  37. /* 绕着Y轴转 */
  38. @keyframes rotate1 {
  39. 0% {
  40. transform: rotateY(0);
  41. }
  42. 100% {
  43. transform: rotateY(360deg);
  44. }
  45. }
  46. /* 绕着X轴转 */
  47. @keyframes rotate2 {
  48. 0% {
  49. transform: rotateX(0);
  50. }
  51. 100% {
  52. transform: rotateX(360deg);
  53. }
  54. }
  55. /* 绕着Z轴转 */
  56. @keyframes rotate3 {
  57. 0% {
  58. transform: rotateZ(0);
  59. }
  60. 100% {
  61. transform: rotateZ(360deg);
  62. }
  63. }
  64. </style>
  65. <div class="container">
  66. <img src="./img/1.png" alt="">
  67. <img src="./img/2.jpg" alt="">
  68. <img src="./img/3.jpg" alt="">
  69. </div>
  70. </body>
  71. </html>

动画4(点击收缩隐藏)

  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. </head>
  9. <body>
  10. <style>
  11. * {
  12. padding: 0;
  13. margin: 0;
  14. box-sizing: border-box;
  15. }
  16. .box {
  17. width: 500px;
  18. height: 500px;
  19. border: 1px solid red;
  20. margin: 100px 0 0 100px;
  21. position: relative;
  22. overflow: hidden;
  23. }
  24. .move {
  25. width: 30%;
  26. height: 70%;
  27. border: 1px solid blue;
  28. border-radius: 10px;
  29. position: absolute;
  30. right: -150px;
  31. top: 15%;
  32. }
  33. #btn {
  34. position: absolute;
  35. top: 50%;
  36. right: 0;
  37. transform: translateY(-50%);
  38. }
  39. .show {
  40. animation: rotate1 0.4s linear;
  41. /* 动画执行一次 */
  42. animation-iteration-count: 1;
  43. /* 停留在最后一帧 */
  44. animation-fill-mode: both;
  45. }
  46. .hide {
  47. animation: rotate2 0.4s linear;
  48. /* 动画执行一次 */
  49. animation-iteration-count: 1;
  50. /* 停留在最后一帧 */
  51. animation-fill-mode: both;
  52. }
  53. /* 向左移动 */
  54. @keyframes rotate1 {
  55. 0% {
  56. transform: translateX(0);
  57. }
  58. 100% {
  59. transform: translateX(-150px);
  60. }
  61. }
  62. /* 向右移动 */
  63. @keyframes rotate2 {
  64. 0% {
  65. transform: translateX(-150px);
  66. }
  67. 100% {
  68. transform: translateX(0);
  69. }
  70. }
  71. </style>
  72. <div class="box">
  73. <div class="move"></div>
  74. <button id="btn"></button>
  75. </div>
  76. <script>
  77. // DOM.classList -> 返回一个元素的类属性的实时 DOMTokenList 集合。
  78. // DOM.classList.add('class1', 'class2', 'class3') // 添加一个或多个类名
  79. // DOM.classList.remove('class1', 'class2', 'class3') // 删除一个或多个类名
  80. // DOM.classList.toggle('class1', 'class2', 'class3') // 切换类名(有则移除,没有则添加(切换效果))
  81. let flag = true // true -> 点击展示, false -> 点击隐藏
  82. const $ = name => document.querySelector(name)
  83. $('#btn').innerHTML = '点击展开'
  84. $('#btn').onclick = () => {
  85. if (flag) {
  86. $('.move').classList.remove('hide');
  87. $('.move').classList.add('show');
  88. setTimeout(() => {
  89. $('#btn').innerHTML = '点击收起'
  90. }, 400)
  91. } else {
  92. $('.move').classList.remove('show');
  93. $('.move').classList.add('hide');
  94. setTimeout(() => {
  95. $('#btn').innerHTML = '点击展开'
  96. }, 400)
  97. }
  98. flag = !flag
  99. }
  100. </script>
  101. </body>
  102. </html>

感谢大家支持学习

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/266218?site
推荐阅读
相关标签
  

闽ICP备14008679号