准备一个div

  1. <div class="loading"></div>

涟漪效果

  1. .loading {
  2. position: relative;
  3. width: 100px;
  4. height: 100px;
  5. }
  6. .loading::before, .loading::after {
  7. content: '';
  8. position: absolute;
  9. left: 0;
  10. top: 0;
  11. bottom: 0;
  12. right: 0;
  13. margin: auto;
  14. background: #b4b8f9;
  15. border-radius: 50%;
  16. animation: wave 1.5s infinite linear;
  17. }
  18. .loading::after {
  19. animation-delay: 0.75s;
  20. }
  21. @keyframes wave {
  22. 0% {width: 0; height: 0; opacity: 1;}
  23. 100% {width: 100px; height: 100px; opacity: 0;}
  24. }

2.gif

呼吸效果

  1. .loading {
  2. position: relative;
  3. width: 200px;
  4. height: 200px;
  5. }
  6. .loading::before, .loading::after {
  7. content: '';
  8. position: absolute;
  9. left: 0;
  10. top: 0;
  11. bottom: 0;
  12. right: 0;
  13. margin: auto;
  14. background: #b4b8f9;
  15. border-radius: 50%;
  16. animation: wave 1.5s infinite linear;
  17. }
  18. .loading::after {
  19. animation-direction: reverse;
  20. }
  21. @keyframes wave {
  22. 0% {width: 0; height: 0; opacity: 1;}
  23. 100% {width: 100px; height: 100px; opacity: 0.5;}
  24. }

3.gif

svg 动画

动画.gif

  1. <div id="container">
  2. <svg viewBox="0 0 100 100">
  3. <defs>
  4. <filter id="shadow">
  5. <feDropShadow dx="0" dy="0" stdDeviation="1.5"
  6. flood-color="#40a9ff"/>
  7. </filter>
  8. </defs>
  9. <circle id="spinner" style="fill:transparent;stroke:#40a9ff;stroke-width: 7px;stroke-linecap: round;filter:url(#shadow);" cx="50" cy="50" r="45"/>
  10. </svg>
  11. </div>
  1. div {
  2. position: absolute;
  3. top: 50%;
  4. left: 50%;
  5. transform: translate(-50%,-50%);
  6. }
  7. #container {
  8. width: 200px;
  9. height: 200px;
  10. }
  11. @keyframes animation {
  12. 0% {
  13. stroke-dasharray: 1 98;
  14. stroke-dashoffset: -105;
  15. }
  16. 50% {
  17. stroke-dasharray: 80 10;
  18. stroke-dashoffset: -160;
  19. }
  20. 100% {
  21. stroke-dasharray: 1 98;
  22. stroke-dashoffset: -300;
  23. }
  24. }
  25. #spinner {
  26. transform-origin: center;
  27. animation-name: animation;
  28. animation-duration: 1.2s;
  29. animation-timing-function: cubic-bezier;
  30. animation-iteration-count: infinite;
  31. }

更多参考