天天看點

【每日一練】69—CSS實作一個牛奶加載動畫

【每日一練】69—CSS實作一個牛奶加載動畫

今天開始我們的第69練,一個加載動畫案例的實作,其實,關于加載動畫的練習或者源碼素材,我都在之前的文章裡分享了很多,有實用型的也有好玩有趣型的,而今天這個練習,是一個好玩有趣型的加載動畫練習,希望你會喜歡。

具體的效果請看下面截圖:

【每日一練】69—CSS實作一個牛奶加載動畫

具體的實作代碼如下:

HTML代碼:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>【每日一練】69—CSS實作一個牛奶加載動畫</title>
</head>
<body>
  <div class="container">
    <h2>牛奶</h2>
    <div class="loader">
      <span style="--i:0;"></span>
      <span style="--i:1;"></span>
      <span style="--i:2;"></span>
      <span style="--i:3;"></span>
      <span style="--i:4;"></span>
      <span style="--i:5;"></span>
      <span style="--i:6;"></span>
      <span style="--i:7;"></span>
    </div>
  </div>
  <svg>
    <filter id="gooey">
      <feGaussianBlur in="SourceGraphic" stdDeviation="10" />
      <feColorMatrix values="
                            1 0 0 0 0
                            0 1 0 0 0
                            0 0 1 0 0
                            0 0 0 20 -10"
                      />
    </filter>
  </svg>
</body>
</html>      

CSS代碼:

*
{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Oleo Script Swash Caps', cursive;
}
body 
{
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(45deg,#006bc6,#1ecafc);
}
.container 
{
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}
.container h2 
{
  position: absolute;
  color: #fff;
  font-size: 1.75em;
  font-weight: 500;
}
.loader
{
  position: relative;
  width: 300px;
  height: 300px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0,0,0,0.25);
  filter: url(#gooey);
}
.loader span
{
  position: absolute;
  left: 0px;
  transform-origin: 150px;
  width: 60px;
  height: 60px;
  background: #fff;
  border-radius: 50%;
  animation: animate 5s ease-in-out infinite;
  animation-delay: calc(0.15s * var(--i));
}
@keyframes animate 
{
  0%,10% 
  {
    width: 100px;
    height: 100px;
    transform: rotate(0deg) translateX(120px);
  }
  40%,70% 
  {
    width: 40px;
    height: 40px;
    transform: rotate(calc(360deg / 8 * var(--i)));
    box-shadow: 0 0 0 10px #fff;
  }
  90%,100% 
  {
    width: 100px;
    height: 100px;
    transform: rotate(0deg) translateX(120px);
  }
}
svg
{
    width: 0;
    height: 0;
}      

寫在最後

以上就是今天【每日一練】的全部内容,希望今天的小練習對你有用,如果你覺得有幫助的話,請點贊我,并将它分享給你身邊做開發的朋友,也許能夠幫助到他。

我是楊小愛,我們明天見。