效果如下

02.gif

View部分

  1. <div id="app">
  2. <div class="heart-loading">
  3. <div class="ul" style= "--line-count: 9">
  4. <div class="li" v-for="v in 9" :key="v" :class="`line-${v}`" :style="`--line-index: ${v}`"></div>
  5. </div>
  6. </div>
  7. </div>

JS部分

  1. var app = new Vue({
  2. el: '#app',
  3. data() {
  4. return {
  5. }
  6. },
  7. methods: {
  8. }
  9. });

css 部分

  1. .heart-loading {
  2. width: 200px;
  3. height: 200px;
  4. background-color: #369;
  5. display: flex;
  6. justify-content: center;
  7. align-items: center;
  8. }
  9. .ul {
  10. display: flex;
  11. justify-content: space-between;
  12. width: 150px;
  13. height: 10px;
  14. }
  15. .li {
  16. --v: calc(var(--line-index) / var(--line-count) * .5turn);
  17. --time: calc((var(--line-index) - 1) * 40ms);
  18. border-radius: 5px;
  19. width: 10px;
  20. height: 10px;
  21. background-color: #3c9;
  22. filter: hue-rotate(var(--v));
  23. animation-duration: 1s;
  24. animation-delay: var(--time);
  25. animation-iteration-count: infinite;
  26. }
  27. .line-1, .line-9 {
  28. animation-name: line-move-1;
  29. }
  30. .line-2, .line-8 {
  31. animation-name: line-move-2;
  32. }
  33. .line-3, .line-7 {
  34. animation-name: line-move-3;
  35. }
  36. .line-4, .line-6 {
  37. animation-name: line-move-4;
  38. }
  39. .line-5 {
  40. animation-name: line-move-5;
  41. }
  42. @keyframes line-move-1 {
  43. 0%,
  44. 10%,
  45. 90%,
  46. 100% {
  47. height: 10px;
  48. }
  49. 45%,
  50. 55% {
  51. height: 30px;
  52. transform: translate3d(0, -15px, 0);
  53. }
  54. }
  55. @keyframes line-move-2 {
  56. 0%,
  57. 10%,
  58. 90%,
  59. 100% {
  60. height: 10px;
  61. }
  62. 45%,
  63. 55% {
  64. height: 60px;
  65. transform: translate3d(0, -30px, 0);
  66. }
  67. }
  68. @keyframes line-move-3 {
  69. 0%,
  70. 10%,
  71. 90%,
  72. 100% {
  73. height: 10px;
  74. }
  75. 45%,
  76. 55% {
  77. height: 80px;
  78. transform: translate3d(0, -40px, 0);
  79. }
  80. }
  81. @keyframes line-move-4 {
  82. 0%,
  83. 10%,
  84. 90%,
  85. 100% {
  86. height: 10px;
  87. }
  88. 45%,
  89. 55% {
  90. height: 90px;
  91. transform: translate3d(0, -30px, 0);
  92. }
  93. }
  94. @keyframes line-move-5 {
  95. 0%,
  96. 10%,
  97. 90%,
  98. 100% {
  99. height: 10px;
  100. }
  101. 45%,
  102. 55% {
  103. height: 90px;
  104. transform: translate3d(0, -20px, 0);
  105. }
  106. }