<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à) 067

          共 3719字,需瀏覽 8分鐘

           ·

          2021-06-07 00:19

          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 {
            width8px;
            height48px;
            display: inline-block;
            position: relative;
            border-radius4px;
            left: -40px;
            animation: loading 1s linear infinite alternate;
          }

          @keyframes loading {
            0% {
              box-shadow20px 0 rgba(2552552550.25), 40px 0 rgba(2552552551), 60px 0 rgba(2552552551);
            }
            50% {
              box-shadow20px 0 rgba(2552552551), 40px 0 rgba(2552552550.25), 60px 0 rgba(2552552551);
            }
            100% {
              box-shadow20px 0 rgba(2552552551), 40px 0 rgba(2552552551), 60px 0 rgba(2552552550.25);
            }
          }

          Part3原理詳解

          步驟1

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

          • 相對(duì)定位
          • 寬度為8px 高度為48px
          • 背景色:黑色
          • border-radius: 4px
          span {
          width: 8px;
          height: 48px;
          position: relative;
          background-color: black;
          border-radius: 4px;
          }

          效果圖如下

          步驟2

          將span左移動(dòng)40px

          span {
          left: -40px;
          }

          效果圖如下

          步驟3

          設(shè)置span的三個(gè)陰影

          顏色均為白色,位置關(guān)系為

          box-shadow: 20px 0 rgba(255, 255, 255, 1), /*陰影1*/
          40px 0 rgba(255, 255, 255, 1), /*陰影2*/
          60px 0 rgba(255, 255, 255, 1);/*陰影3*/

          陰影位置如下

          步驟4

          為span的三個(gè)陰影設(shè)置動(dòng)畫(huà)

          通過(guò)使用rgba()函數(shù)設(shè)置每個(gè)陰影的顏色深淺情況

          • rgba(255, 255, 255, 1)表示純白
          • rgba(255, 255, 255, 0.25)表示淺白

          動(dòng)畫(huà)關(guān)鍵有 三幀

          第一幀

          • 陰影1為淺白色
          • 陰影2、3為純白色
          box-shadow: 20px 0 rgba(255, 255, 255, 0.25), 40px 0 rgba(255, 255, 255, 1), 60px 0 rgba(255, 255, 255, 1);

          效果圖如下

          第二幀

          • 陰影2為淺白色
          • 陰影1、2為純白色

          效果圖如下

          第三幀

          • 陰影3為淺白色
          • 陰影1、2為純白色

          效果圖如下

          使用animation設(shè)置動(dòng)畫(huà)從第一幀均為過(guò)渡至第三幀再過(guò)渡至第一幀

          animation: loading 1s linear infinite alternate;
          @keyframes loading {
          0% {
          box-shadow: 20px 0 rgba(255, 255, 255, 0.25), 40px 0 rgba(255, 255, 255, 1), 60px 0 rgba(255, 255, 255, 1);
          }
          50% {
          box-shadow: 20px 0 rgba(255, 255, 255, 1), 40px 0 rgba(255, 255, 255, 0.25), 60px 0 rgba(255, 255, 255, 1);
          }
          100% {
          box-shadow: 20px 0 rgba(255, 255, 255, 1), 40px 0 rgba(255, 255, 255, 1), 60px 0 rgba(255, 255, 255, 0.25);
          }
          }

          效果圖如下

          步驟5

          注釋掉span背景色

          最終效果圖如下

          Part4結(jié)語(yǔ)

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

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

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

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

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

          謝謝支持??

          瀏覽 49
          點(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>
                  婷婷淫淫网 | 国产成人精品一区二区毛片 | 伊人69 | 天天爽av | 亚洲在线免费视频 |