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

          共 3340字,需瀏覽 7分鐘

           ·

          2021-05-05 13:26

          效果展示

          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

          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;
            position: relative;
          }
          span::before,
          span::after{
            position: absolute;
            content'';
            width96px;
            height96px;
            top0;
            left0;
            background: white;
            border-radius50%;
            animation: animloader 4s ease-in-out infinite;
          }
          span::after{
            animation-delay2s;
          }
            
          @keyframes animloader {
            0% , 100%{ transformscale(0); opacity1;}
            50% { transformscale(1); opacity0;}
          }

          原理詳解

          步驟1

          使用span標簽,設置為

          • 寬度、高度均為96px
          • 相對定位
           width: 96px;
            height: 96px;
            position: relative;

          步驟2

          利用span::before、span::after偽類元素作為白色圓圈部分

          設置為

          • 絕對定位(top:0 left:0)
          • 寬度、高度均為96px(與span完全重疊)
          • 背景色:白色
          position: absolute;
            content: '';
            width: 96px;
            height: 96px;
            top: 0;
            left: 0;
            background: white;

          效果圖如下

          步驟3

          span::before、span::after圓角化

          border-radius: 50%;

          效果圖如下

          步驟4

          為span::before、span::after添加動畫

          有三種狀態(tài)

          • 初始(0%):大小為0(相對于原大?。?,顏色為(白,透明級別1)
          • 中間(50%):大小為1(相對于原大?。?,顏色為(白,透明級別0)
          • 末尾(100%):大小為0(相對于原大?。伾珵椋ò?,透明級別1)

          變換過程

          • 大?。?-->1-->0
          • 顏色:白色逐漸變淺,再逐漸變深
          animation: animloader 4s ease-in-out infinite;

          @keyframes animloader {
            0%, 100% {
              transform: scale(0);
              opacity: 1;
            }
            50% {
              transform: scale(1);
              opacity: 0;
            }
          }

          效果圖如下

          步驟5

          從步驟4效果圖可以看出

          只有一個白色圓圈

          而其實我們是設置了兩個(一個before,一個after)

          為了視覺上顯示兩個白色圓圈

          我們對after進行動畫延時

          這樣同一時刻就可以看到兩個白色圓圈啦

          animation-delay: 2s;

          效果圖如下

          結語

          學習來源:

          ?

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

          文章僅作為學習筆記,記錄從0到1的一個過程。

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

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

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

          謝謝支持??


          瀏覽 64
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

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

          手機掃一掃分享

          分享
          舉報
          <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>
                  wwwwww在线 | 久操操操| 日韩欧美mv国产 | 日批网站在线 | 99精品A√|