<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          【動(dòng)畫(huà)消消樂(lè)】HTML+CSS 自定義加載動(dòng)畫(huà) 070

          共 3574字,需瀏覽 8分鐘

           ·

          2021-06-07 00:20

          Part1效果展示

          Part2Demo代碼

          HTML

          <!DOCTYPE html>
          <html lang="en">
          <head>
              <meta charset="UTF-8">
              <meta http-equiv="X-UA-Compatible" content="IE=edge">
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <link rel="stylesheet" href="style.css">
              <title>Document</title>
          </head>
          <body>
              <section><span></span></section>
          </body>
          </html>

          CSS

          htmlbody {
            margin0;
            height100%;
          }

          body {
            display: flex;
            justify-content: center;
            align-items: center;
            background#ed556a;
            /* background-color: #82466e; */
            animation: backColor 4s infinite;
          }

          section {
            width650px;
            height300px;
            padding10px;
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            border2px solid white;
          }

          span {
            width5px;
            height5px;
            display: inline-block;
            position: relative;
            border-radius4px;
            color: white;
            background: currentColor;
            animation: animloader66 0.6s 0.6s linear infinite alternate;
          }

          span::beforespan::after {
            content'';
            width5px;
            height5px;
            border-radius4px;
            background: currentColor;
            position: absolute;
            left0;
            top15px;
            animation: animloader66 0.6s 0.9s linear infinite alternate;
          }

          [data-index="66"] {
            justify-content: normal;
            padding-left15%;
          }

          span::after {
            top: -15px;
            animation-delay0s;
          }

          @keyframes animloader66 {
            0% {
              width5px;
            }
            100% {
              width48px;
            }
          }

          Part3原理詳解

          步驟1

          使用span標(biāo)簽,設(shè)置為

          • 相對(duì)定位
          • 寬度、高度均為5px
          • 背景色:白色
          • color:白色
          • border-radius: 4px
          span {
          width: 5px;
          height: 5px;
          position: relative;
          border-radius: 4px;
          color: white;
          background: white;
          }

          效果圖如下

          步驟2

          為span添加動(dòng)畫(huà)

          動(dòng)畫(huà)描述效果為:span寬度從5px變化到48px,再回到5px

          span {
          animation: loading 0.6s 0s linear infinite alternate;
          }
          @keyframes loading {
          0% {
          width: 5px;
          }
          100% {
          width: 48px;
          }
          }

          效果圖如下

          注:span事先是設(shè)置固定在頁(yè)面正中的,所以才會(huì)出現(xiàn)上圖效果

          步驟3

          使用span的兩個(gè)偽元素:span::before、span::after

          同時(shí)設(shè)置為

          • 絕對(duì)定位(  left: 0  top: 15px)
          • 寬度、高度均為5px
          • 背景色:白色
          • border-radius: 4px
          span::before, span::after {
          content: '';
          width: 5px;
          height: 5px;
          border-radius: 4px;
          background: white;
          position: absolute;
          left: 0;
          top: 15px;
          }

          位置關(guān)系如下

          為span::before、span::after添加同span一樣的動(dòng)畫(huà),只是動(dòng)畫(huà)開(kāi)始延遲時(shí)間設(shè)置為0.6s

          span::before, span::after {
          animation: loading 0.6s 0.6s linear infinite alternate;
          }

          效果圖如下:

          注:可以發(fā)現(xiàn),span和它的兩個(gè)偽元素的左部分一直是處于同一條直線上

          步驟4

          分離span::before、span::after

          將span::after移動(dòng)至位于span上方15px處 且動(dòng)畫(huà)延遲時(shí)間修改為0.9s

          span::after {
          top: -15px;
          animation-delay: 0.9s;
          }

          得到最終的效果圖

          Part4結(jié)語(yǔ)

          希望對(duì)您有所幫助

          如有錯(cuò)誤歡迎小伙伴指正~

          我是 海轟?(?ˊ?ˋ)?

          如果您覺(jué)得寫(xiě)得可以的話

          請(qǐng)點(diǎn)個(gè)贊吧

          謝謝支持??


          瀏覽 71
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  天天日日日 | 精品久久成人无码片 | 国产亚洲欧美视频 | 人人操人人爱人人摸 | 眼镜人妻在线视频不卡 |