1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

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

        共 5590字,需瀏覽 12分鐘

         ·

        2021-04-27 09:28

        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 transparent;
          border-radius50%
          position: relative;
          animation: rotation 2s linear infinite;
        }
        span::before{
          position: absolute;
          content'';
          left0;
          right0;
          top0;
          bottom0;
          margin: auto;
          width:  56px;
          height:  56px;
          border10px solid;
          border-color: transparent transparent red red; 
          border-radius50%;
          /* 注意這里的時(shí)間 */
          animation: rotationback 1s linear infinite;

         span::after{
          position: absolute;
          content'';
          left0;
          right0;
          top0;
          bottom0;
          margin: auto;
          width:  24px;
          height:  24px;
          border10px solid; 
          border-radius50%;
          border-color:  white white transparent transparent;
          /* 注意這里的時(shí)間 */ 
          animation: rotation 3s linear infinite;
         } 

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

        Part3原理詳解

        步驟1

        利用span標(biāo)簽,生成一個(gè)正方形

        • 寬度、高度均為96px
        • 邊框:10px solid ;
         width : 96px;
          height: 96px;
          border: 10px solid ;

        效果圖如下

        步驟2

        上/右邊框顏色設(shè)置為白色,下/左邊框顏色為透明

        border-color: white white transparent transparent;

        效果圖如下

        步驟3

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

        • 絕對(duì)定位
        • 寬度、高度均為56px
        • 邊框:10px solid
        • 位于span正中央(上下左右居中)
        position: absolute;
          content: '';
          
          /* 上下左右居中 絕對(duì)定位時(shí)*/
          left: 0;
          right: 0;
          top: 0;
          bottom: 0;
          margin: auto;
          
          width:  56px;
          height:  56px;
          border: 10px solid;

        效果圖如下

        步驟4

        span::before設(shè)置邊框顏色

        • 下/左邊框顏色為紅色
        • 上/右邊框顏色為透明
        border-color: transparent transparent red red;

        效果圖如下

        步驟5

        設(shè)置span::after元素

        • 寬度、高度均為24px
        • 邊框:10px solid
        • 絕對(duì)定位
        • 位于span正中央(上下左右居中)
          position: absolute;
          content: '';
          
          /*上下左右居中*/
          left: 0;
          right: 0;
          top: 0;
          bottom: 0;
          margin: auto;
          
          width:  24px;
          height:  24px;
          border: 10px solid; 

        效果圖如下

        步驟6

        設(shè)置span::after的邊框顏色

        • 上/右邊框顏色為白色
        • 下/左邊框顏色為透明
        border-color:  white white transparent transparent;

        效果圖如下

        步驟7

        對(duì)span、span::before、span::after圓角化

        border-radius: 50%;

        效果圖如下

        步驟8

        為span添加動(dòng)畫

        • 順時(shí)針 2s 無限循環(huán)
        animation: rotation 2s linear infinite;
        @keyframes rotation {
          0% { transform: rotate(0deg) }
          100% { transform: rotate(360deg)
          }
        }

        效果圖如下

        步驟9

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

        • 逆時(shí)針 1s 無限循環(huán)
         animation: rotationback 1s linear infinite;
        @keyframes rotationback {
          0% { transform: rotate(360deg) }
          100% { transform: rotate(0deg)
          }
        }

        效果圖如下

        步驟10

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

        • 順時(shí)針 3s 無限循環(huán)
        animation: rotation 3s linear infinite;
        @keyframes rotationback {
          0% { transform: rotate(360deg) }
          100% { transform: rotate(0deg)
          }
        }

        效果圖如下

        Part4結(jié)語

        學(xué)習(xí)來源:

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

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

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

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

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

        謝謝支持??


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

        手機(jī)掃一掃分享

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

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            女久久久| 污污污污污污污污污网站在线播放 | 91喷水| 男女怕怕网站 | 男人日女人下面视频 | 骚屄网| 99热国产在线观看 | 国产精品偷窥熟女精品图片 | 一级黄片直播 | ass日本少妇pics |