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

          「HTML+CSS」自定義加載動(dòng)畫【014】

          共 3870字,需瀏覽 8分鐘

           ·

          2021-04-27 09:27

          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

          html,body{
            margin0;
            height100%;
          }
          body{
            display: flex;
            justify-content: center;
            align-items: center;
            background#263238;
          }
          section {
              width650px;
              height300px;
              padding10px;
              position: relative;
              display: flex;
              align-items: center;
              justify-content: center;
              /* 紅色邊框僅作提示 */
              border2px solid red;
          }

          span{
            width 96px;
            height96px;
            border10px solid ;
            border-color: white white transparent;
            border-radius50%
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            animation: rotation 2s linear infinite;
          }
          span::before{
            position: relative;
            content'';
            width:  48px;
            height:  48px;
            border10px solid;
            border-color: transparent red red;
            border-radius50%;
            /* 注意這里的時(shí)間 */
            animation: rotationback 1s linear infinite;
          }

          @keyframes rotation {
            0% { transformrotate(0deg) }
            100% { transformrotate(360deg)
            }
          }
          @keyframes rotationback {
            0% { transformrotate(360deg) }
            100% { transformrotate(0deg)
            }
          }

          Part3原理詳解

          步驟1

          設(shè)置span標(biāo)簽

          • 寬度、長(zhǎng)度均為96px
          • 邊框:10px solid

          效果圖如下

          步驟2

          設(shè)置span標(biāo)簽

          • 上/左/右邊框顏色為白色
          • 下邊框?yàn)橥该?/section>
          border-color: white white transparent;

          效果圖如下

          步驟3

          設(shè)置span::before偽類

          • 寬度、高度均為48px
          • 下/左/右邊框?yàn)榧t色 10px solid
          • 上邊框?yàn)橥该?/section>
          width:  48px;
            height:  48px;
            border: 10px solid;
            border-color: transparent red red;

          再設(shè)置span標(biāo)簽為flex布局,使得span::before位于span正中間(上下左右居中)

            display: flex;
            align-items: center;
            justify-content: center;

          效果圖如下

          步驟4

          span、span::before圓角化

          border-radius: 50%;

          效果圖如下

          步驟5

          為span添加動(dòng)畫

          • 順時(shí)針旋轉(zhuǎn)
          animation: rotation 2s linear infinite;
          /* 順時(shí)針旋轉(zhuǎn)動(dòng)畫*/
          @keyframes rotation {
            0% { transform: rotate(0deg) }
            100% { transform: rotate(360deg)
            }
          }

          效果圖如下

          注意:此時(shí)紅色部分是和白色部分同方向旋轉(zhuǎn)

          步驟6

          為span::before添加動(dòng)畫

          • 逆時(shí)針旋轉(zhuǎn)
          /*注意這里的時(shí)間*/
          animation: rotationback 1s linear infinite;
          @keyframes rotationback {
            0% { transform: rotate(360deg) }
            100% { transform: rotate(0deg)
            }
          }

          效果圖如下

          注意:此時(shí)紅色部分和白色部分旋轉(zhuǎn)方向相反

          Part4結(jié)語(yǔ)

          學(xué)習(xí)來(lái)源:

          https://codepen.io/bhadupranjal/pen/vYLZYqQ

          文章僅作為學(xué)習(xí)筆記,記錄從0到1的一個(gè)過(guò)程。

          希望對(duì)您有所幫助,如有錯(cuò)誤歡迎小伙伴指正~

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

          如果您覺(jué)得寫得可以的話請(qǐng)點(diǎn)個(gè)贊吧

          謝謝支持??


          瀏覽 23
          點(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>
                  中文字幕天堂网 | 91一区二区三区综合网 | 一区二区三区亚洲动漫 | 国产AV小电影 | 台湾精品一区二区三区四区 |