Skip to content
HangoverHangover
首页
项目收藏
留言板
github icon
  • 代码片段

      • loading动画

    loading动画

    author iconHangovercalendar icon2022年4月19日category icon
    • CSS动画
    tag icon
    • css
    • loading
    • 动画
    timer icon小于 1 分钟

    通过设置不同的延迟时间,达到动画交错播放的效果

    <div class="loading">
      <div class="dot"></div>
      <div class="dot"></div>
      <div class="dot"></div>
      <div class="dot"></div>
      <div class="dot"></div>
    </div>
    
    1
    2
    3
    4
    5
    6
    7
    body {
      display: flex;
      height: 100vh;
      justify-content: center;
      align-items: center;
    }
    
    .loading {
      display: flex;
    }
    .loading .dot {
      position: relative;
      width: 2em;
      height: 2em;
      margin: 0.8em;
      border-radius: 50%;
    }
    .loading .dot::before {
      position: absolute;
      content: "";
      width: 100%;
      height: 100%;
      background: inherit;
      border-radius: inherit;
      animation: wave 2s ease-out infinite;
    }
    .loading .dot:nth-child(1) {
      background: #7ef9ff;
    }
    .loading .dot:nth-child(1)::before {
      animation-delay: 0.2s;
    }
    .loading .dot:nth-child(2) {
      background: #89cff0;
    }
    .loading .dot:nth-child(2)::before {
      animation-delay: 0.4s;
    }
    .loading .dot:nth-child(3) {
      background: #4682b4;
    }
    .loading .dot:nth-child(3)::before {
      animation-delay: 0.6s;
    }
    .loading .dot:nth-child(4) {
      background: #0f52ba;
    }
    .loading .dot:nth-child(4)::before {
      animation-delay: 0.8s;
    }
    .loading .dot:nth-child(5) {
      background: #000080;
    }
    .loading .dot:nth-child(5)::before {
      animation-delay: 1s;
    }
    
    @keyframes wave {
      50%, 75% {
        transform: scale(2.5);
      }
      80%, 100% {
        opacity: 0;
      }
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    Demo
    鸟无声兮山寂寂,夜正长兮风淅淅。 ──李华《吊古战场文》
    Copyright © 2023 Hangover