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」自定義加載動畫【010】

        共 4120字,需瀏覽 9分鐘

         ·

        2021-04-25 13:15

        效果展示

        思路

        這里用span元素代表外層白色圓圈

        兩個紅色小球分別用span的兩個偽類::before和::after代表

        根據(jù)效果圖,可以大概得出思路

        • 先利用span生成一個正方形,設(shè)置好邊框
        • 兩個偽類元素為絕對定位,分別位于正方形的左上和右下
        • 然后分別對其進行圓角處理
        • 最后添加旋轉(zhuǎn)動畫即可

        Demo代碼

        HTML

        <!DOCTYPE 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 white;
          border-radius50%
          display: flex;
          align-items: center;
          justify-content: center;
          position: relative;
          animation: rotation 2s linear infinite;
        }
        span::before{
          position: absolute;
          content'';
          top15px;
          left15px;
          width:  20px;
          height:  20px;
          background: red;
          border-radius50%;
        }
        span::after{
          position: absolute;
          content'';
          bottom15px;
          right15px;
          width:  20px;
          height:  20px;
          background: red;
          border-radius50%;
        }
        @keyframes rotation {
          0% { transformrotate(0deg) }
          100% { transformrotate(360deg)
          }
        }

        原理詳解

        步驟1

        將span元素設(shè)置為

        • 一個96??96px的正方形
        • 邊框為10px,白色,solid
            width : 96px;
            height: 96px;
            border: 10px solid #fff;

        效果圖如下

        步驟2

        span::before和span::after設(shè)置

        • 寬度、高度均為20px
        • 絕對定位,其中before位于左上,after位于右下
        • 背景色為紅色
        /* before的設(shè)置*/
        position: absolute;
          content: '';
          top: 0;
          left: 0;
          width:  20px;
          height:  20px;
          background: red;
          
          /*after的設(shè)置*/
          position: absolute;
          content: '
        ';
          bottom: 0;
          right: 0;
          width:  20px;
          height:  20px;
          background: red;

        效果圖如下

        步驟3

        稍微向正方形中心移動下::before和::after

        /* before的設(shè)置*/
          top: 15px;
          left: 15px;
         
          /*after的設(shè)置*/
          bottom: 15px;
          right: 15px;

        效果圖如下

        步驟4

        對span、span::before、span::after設(shè)置圓角

        border-radius: 50%;

        效果圖如下

        步驟5

        為span添加動畫

        animationrotation 1s linear infinite;
        /*動畫實現(xiàn)*/
          @keyframes rotation {
            0% { transformrotate(0deg) }
            100% { transformrotate(360deg)
            }

        效果圖如下

        結(jié)語

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

        ?

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

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

        希望對您有所幫助,如有錯誤歡迎小伙伴指正~

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

        如果您覺得寫得可以的話請點個贊吧

        謝謝支持??


        瀏覽 52
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        評論
        圖片
        表情
        推薦
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        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>
            黑人性生活片 | 九哥日逼网| 在线无码成人中学 | 天天艹在线观看 | 99成人乱码一区二区三区在线豆花视频 | 女生扒开尿口给男生捅38分钟 | 办公室女职员交换性bd | 影音先锋新男人av资源网站 | 99爱视频在线观看 | 恋综被各种啪h怀孕 |