<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)畫消消樂(lè)】HTML+CSS 自定義加載動(dòng)畫 058

          共 3007字,需瀏覽 7分鐘

           ·

          2021-06-07 00:24

          效果展示

          Demo代碼

          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;
          }

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

          span {
            width48px;
            height96px;
            display: inline-block;
            position: relative;
            color: white;
            border3px solid;
            animation: loading 2s linear infinite alternate;
          }

          span::before {
            content'';
            position: absolute;
            top: -15px;
            left6px;
            width36px;
            height12px;
            background-color: white;
          }

          @keyframes loading {
            0% {
              box-shadow0 0 inset
            }
            100% {
              box-shadow0 -96px inset
            }
          }

          原理詳解

          步驟1

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

          • 相對(duì)定位
          • 寬度48px,高度96px
          • 邊框:3px solid 白色
          • color:白色
          span {
          width: 48px;
          height: 96px;
          position: relative;
          color: white;
          border: 3px solid;
          }

          效果圖如下

          步驟2

          利用span::before偽元素,充當(dāng)最上方白色方塊

          設(shè)置為

          • 絕對(duì)定位(top -15px,left 6px)
          • 寬度:36px
          • 高度:12px
          • 背景色:白色
          span::before {
          content: '';
          position: absolute;
          top: -15px;
          left: 6px;
          width: 36px;
          height: 12px;
          background-color: white;
          }

          效果圖如下

          注:

          • top是-15px,是因?yàn)樯戏桨咨綁K寬度12px,還需要加上下方白色邊框3px,一共12+3=15px
          • left為6px,是因?yàn)橐股戏桨咨綁K居中,需要向左移動(dòng)(48-36)/2=6px

          步驟3

          使用span的陰影(box-shadow)作為動(dòng)畫

          需要實(shí)現(xiàn)的效果:逐漸填充下方白色部分內(nèi)部

          • 陰影向內(nèi)

          以動(dòng)畫中的幾幀說(shuō)明:

          當(dāng)陰影向內(nèi)延伸10px時(shí)

          span {
          box-shadow: 0 -10px inset
          }

          效果圖如下

          當(dāng)陰影向內(nèi)延伸48px時(shí)

          span {
          box-shadow: 0 -48px inset
          }

          效果圖如下

          當(dāng)陰影向內(nèi)延伸96px時(shí)

          span {
          box-shadow: 0 -96px inset
          }

          效果圖如下

          綜上:陰影向內(nèi)從0延伸96px,重復(fù)即可

          animation: loading 2s linear infinite ;
          @keyframes loading {
          0% {
          box-shadow: 0 0 inset
          }
          100% {
          box-shadow: 0 -96px inset
          }
          }

          效果圖如下

          步驟4

          設(shè)置動(dòng)畫交替進(jìn)行

          animation: loading 2s linear infinite alternate;

          效果圖如下

          結(jié)語(yǔ)

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

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

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

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

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

          謝謝支持??


          瀏覽 50
          點(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>
                  jiujiujiu999 | HD国产人妖TS另类视频 | 成人三级视频在线 | 亚洲v在线 | 波多野结衣av一区二区全免费观看 |