css动画:全局loading效果实现

54 阅读1分钟
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>demo</title>
    <style>
      .loading {
        width: 100%;
        height: 100%;
        background-color: #fff;
        position: absolute;
      }
      .loading h2 {
        color: #666;
        margin: 0;
        letter-spacing: 0.1em;
        font-size: 20px;
        font-weight: 400;
        font-family: Arial, Helvetica, sans-serif;
      }
      .loading .container {
        width: 200px;
        height: 80px;
        text-align: center;
        z-index: 1;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
      }
      .loading span {
        display: inline-block;
        width: 0.6em;
        height: 0.6em;
        margin: 0.19em;
        background-color: #4f00ff;
        border-radius: 0.6em;
        vertical-align: middle;
        -webkit-animation: loading 1s infinite alternate;
        animation: loading 1s infinite alternate;
        
      }
      .loading span:nth-of-type(2) {
        background: #7d00ff;
        -webkit-animation-delay: 0.2s;
        animation-delay: 0.2s;
      }
      .loading span:nth-of-type(3) {
        background: #ff00d2;
        -webkit-animation-delay: 0.4s;
        animation-delay: 0.4s;
      }
      .loading span:nth-of-type(4) {
        background: #ff006e;
        -webkit-animation-delay: 0.6s;
        animation-delay: 0.6s;
      }

      .loading span:nth-of-type(5) {
        background: #ff5400;
        -webkit-animation-delay: 0.8s;
        animation-delay: 0.8s;
      }

      .loading span:nth-of-type(6) {
        background: #ff9e00;
        -webkit-animation-delay: 1s;
        animation-delay: 1s;
      }

      .loading span:nth-of-type(7) {
        background: #00ffe0;
        -webkit-animation-delay: 1.2s;
        animation-delay: 1.2s;
      }

      @keyframes loading {
        0% {
          transform: scale(1);
          opacity: 0;
        }
        100% {
          transform: scale(1.1);
          opacity: 1;
        }
      }
    </style>
  </head>
  <body>
    <div class="loading">
      <div class="container">
        <h2>Loading</h2>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
      </div>
    </div>
  </body>
</html>