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

          3分鐘實(shí)現(xiàn)充電水波特效

          共 20647字,需瀏覽 42分鐘

           ·

          2021-06-11 12:45

          點(diǎn)擊上方 前端瓶子君,關(guān)注公眾號(hào)

          回復(fù)算法,加入前端編程面試算法每日一題群

          來(lái)源:北極光之夜

          https://juejin.cn/post/6967360136926986254

          效果(源碼在最后):

          這個(gè)效果跟水波加載動(dòng)畫 html+css是異曲同工之妙的。效果不難實(shí)現(xiàn),但是這個(gè)‘偷天換日’的用法是值得學(xué)習(xí)的。

          實(shí)現(xiàn):

          1. 定義標(biāo)簽,.container是底層盒子也就是電池外形,.water是其中的電量多少,.shadow是背后的陰影:

           <div class="container">
                  <div class="water"></div>
                  <div class="shadow"></div>
              </div>
          復(fù)制代碼

          2. 定義.container的基本樣式:

          .container{
                      position: relative;
                      width200px;
                      height300px;
                      background-colorrgb(255255255);
                      border-radius10px;
                      box-shadow:  0 0 10px rgb(255255255) ;
                  }
          復(fù)制代碼

          position: relative; 相對(duì)定位。background-color: rgb(255, 255, 255); 白色。border-radius: 10px; 角弧度。box-shadow: 0 0 10px rgb(255, 255, 255) ; 陰影。

          3.通過(guò)雙偽類定義電池的頭部:

          .container::after{
                      content'';
                      position: absolute;
                      top: -20px;
                      left50%;
                      width40px;
                      height20px;
                      transformtranslateX(-50%);
                      background-colorrgb(255255255);
                      border-top-right-radius10px;
                      border-top-left-radius10px;
                      box-shadow:  0 0 10px rgb(255255255) ;            
                  }
          復(fù)制代碼

          position: absolute; top: -20px; left: 50%; 定義位置 transform: translateX(-50%); 向左偏移自身的50%,目的是居中。4. 定義電量慢慢變多效果:

           .water{
                      position: absolute;
                      bottom0;
                      width100%;
                      background-imagelinear-gradient(0deg,rgb(9198245),rgb(44243120));
                      border-bottom-right-radius10px;
                      border-bottom-left-radius10px;
                   animation: rise 12s linear forwards;
                    
                       overflow: hidden;
                  }
                  @keyframes rise{
                      0%{
                          height50px;
                      }

                      100%{
                          height80%;            
                          filterhue-rotate(360deg);
                      }
                  }
          復(fù)制代碼

          background-image: linear-gradient(0deg,rgb(9, 198, 245),rgb(44, 243, 120)); 漸變顏色。animation: rise 12s linear forwards; 定義動(dòng)畫,高度改變,相當(dāng)于充電。forwards是指定動(dòng)畫結(jié)束后保留最后一步的屬性。overflow: hidden; 溢出隱藏。filter: hue-rotate(360deg); 色相旋轉(zhuǎn),能使顏色改變。

          5. 定義水波效果(原理是定義一個(gè)有弧度的白色盒子在轉(zhuǎn)動(dòng),其覆蓋掉.water的上面的一部分,.water再定義溢出隱藏,這樣就‘偷天換日’得到一個(gè)白色的波浪):

          .water::after{
                      content'';
                      position: absolute;
                      top: -370px;
                      left: -100px;
                      width400px;
                      height400px;
                      border-radius40%;
                      background-colorrgb(255255255);
                      animation: move 5s linear infinite;
                  }
                  @keyframes move{
                      100%{
                          transformrotate(360deg);
                      }
                  }
          復(fù)制代碼

          位置大小和弧度可以看效果自己設(shè)定。transform: rotate(360deg); 旋轉(zhuǎn)。

          6. 再定義一個(gè)水波,原理一樣,不過(guò)顏色要設(shè)置透明度,免得覆蓋掉另一個(gè)水波:

          .water::before{
                      content'';
                      position: absolute;
                      top: -360px;
                      left: -100px;
                      width400px;
                      height400px;
                      border-radius45%;
                      background-colorrgba(255255255,.5);
                      animation: move2 7s linear infinite;
                  }
                  @keyframes move2{
                      100%{
                          transformrotate(360deg);
                      }
                  }
          復(fù)制代碼

          7. 定義背后的陰影,它的高度和顏色變換應(yīng)該和.water是一致的:

          .shadow{
                      position: absolute;
                      bottom: -8px;
                      left: -3%;
                      width106%;
                      background-imagelinear-gradient(0deg,rgb(9198245),rgb(44243120));
                      z-index: -1;
                   animation: bianse 12s linear forwards;
                  }
                  @keyframes bianse{
                      0%{
                          height50px;
                          filterhue-rotate(0degblur(10px);
                      }

                      100%{
                          height80%;            
                          filterhue-rotate(360degblur(10px);
                      }
                  }
          復(fù)制代碼

          position: absolute; bottom: -8px; left: -3%; width: 106%;位置和大小。z-index: -1; 設(shè)置-1,顯示在最后。filter: hue-rotate(0deg) blur(10px); blur是模糊度。

          完整代碼:

          <!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">
              <title>Document</title>
              <style>
                  *{
                      margin0;
                      padding0;
                      box-sizing: border-box;
                  }
                  body{
                      height100vh;
                      display: flex;
                      justify-content: center;
                      align-items: center;
                      background-colorrgb(189189189);
                  }
                  .container{
                      position: relative;
                      width200px;
                      height300px;
                      background-colorrgb(255255255);
                      border-radius10px;
                      box-shadow:  0 0 10px rgb(255255255) ;
                  }
                  .container::after{
                      content'';
                      position: absolute;
                      top: -20px;
                      left50%;
                      width40px;
                      height20px;
                      transformtranslateX(-50%);
                      background-colorrgb(255255255);
                      border-top-right-radius10px;
                      border-top-left-radius10px;
                      box-shadow:  0 0 10px rgb(255255255) ;

                      
                  }
                 
                 
                  .water{
                      position: absolute;
                      bottom0;
                      width100%;
                      background-imagelinear-gradient(0deg,rgb(9198245),rgb(44243120));
                      border-bottom-right-radius10px;
                      border-bottom-left-radius10px;
                   animation: rise 12s linear forwards;
                    
                       overflow: hidden;
                  }
                  @keyframes rise{
                      0%{
                          height50px;
                      }

                      100%{
                          height80%;            
                          filterhue-rotate(360deg);
                      }
                  }
                  .water::after{
                      content'';
                      position: absolute;
                      top: -370px;
                      left: -100px;
                      width400px;
                      height400px;
                      border-radius40%;
                      background-colorrgb(255255255);
                      animation: move 5s linear infinite;
                  }
                  @keyframes move{
                      100%{
                          transformrotate(360deg);
                      }
                  }
                  .water::before{
                      content'';
                      position: absolute;
                      top: -360px;
                      left: -100px;
                      width400px;
                      height400px;
                      border-radius45%;
                      background-colorrgba(255255255,.5);
                      animation: move2 7s linear infinite;
                  }
                  @keyframes move2{
                      100%{
                          transformrotate(360deg);
                      }
                  }
                  .shadow{
                      position: absolute;
                      bottom: -8px;
                      left: -3%;
                      width106%;
                      background-imagelinear-gradient(0deg,rgb(9198245),rgb(44243120));
                      z-index: -1;
                   animation: bianse 12s linear forwards;
                  }
                  @keyframes bianse{
                      0%{
                          height50px;
                          filterhue-rotate(0degblur(10px);
                      }

                      100%{
                          height80%;            
                          filterhue-rotate(360degblur(10px);
                      }
                  }
              
          </style>
          </head>
          <body>
              <div class="container">
                  <div class="water"></div>
                  <div class="shadow"></div>
              </div>
          </body>
          </html>
          復(fù)制代碼

          總結(jié):

          這個(gè)效果跟水波加載動(dòng)畫 html+css是異曲同工之妙的。效果不難實(shí)現(xiàn),但是這個(gè)‘偷天換日’的用法是值得學(xué)習(xí)的。

          最后

          歡迎關(guān)注【前端瓶子君】??ヽ(°▽°)ノ?
          回復(fù)「算法」,加入前端編程源碼算法群,每日一道面試題(工作日),第二天瓶子君都會(huì)很認(rèn)真的解答喲!
          回復(fù)「交流」,吹吹水、聊聊技術(shù)、吐吐槽!
          回復(fù)「閱讀」,每日刷刷高質(zhì)量好文!
          如果這篇文章對(duì)你有幫助,在看」是最大的支持
           》》面試官也在看的算法資料《《
          “在看和轉(zhuǎn)發(fā)”就是最大的支持


          瀏覽 45
          點(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逼特逼| 99热精品在线观看首页 | 国产亚洲婷婷 |