HTML5+CSS3搭配自定義濾鏡做一個液體環(huán)形小球加載動畫,七個小球繞環(huán)形旋轉,設置有規(guī)律的動畫延遲時間,使它們有序依次旋轉,過程伴隨溶球效果,這真是一個百看不膩的loading加載動畫。
效果:


源碼:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>自定義濾鏡實現(xiàn)液體加載動畫</title>
<link rel="stylesheet" href="../css/26.css">
</head>
<body>
<div class="loading">
<!-- --i是CSS的自定義屬性,通過var函數(shù)可以調用 -->
<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>
<!-- 自定義濾鏡 -->
<svg>
<!-- <filter>標簽用來定義SVG濾鏡 -->
<filter id="gooey">
<!-- <feGaussianBlur>元素是用于創(chuàng)建模糊效果 -->
<feGaussianBlur in="SourceGraphic" stdDeviation="10"></feGaussianBlur>
<!-- <feColorMatrix>是過濾中的一種類型,使用矩陣來影響顏色的每個通道(基于RGBA),你可以將其想象成Photshop中通道編輯一樣 -->
<feColorMatrix values="
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 20 -10
"></feColorMatrix>
</filter>
</svg>
</body>
</html>
*{
/* 初始化 取消頁面內外邊距 */
margin: 0;
padding: 0;
}
body{
/* 彈性布局 水平、垂直居中 */
display: flex;
justify-content: center;
align-items: center;
/* 100%窗口高度 */
height: 100vh;
background-color: #222;
}
svg{
width: 0;
height: 0;
}
.loading{
/* 相對定位 */
position: relative;
width: 200px;
height: 200px;
/* 使用自定義濾鏡gooey */
filter: url(#gooey);
}
.loading span{
/* 絕對定位 */
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: block;
/* 執(zhí)行動畫:動畫名稱 時長 加速后減速 無限次播放 */
animation: animate 4s ease-in-out infinite;
/* 動畫延遲,通過var函數(shù)調用自定義屬性--i,計算出延遲時間 */
animation-delay: calc(0.2s * var(--i));
}
.loading span::before{
content: "";
position: absolute;
top: 0;
left: calc(50% - 20px);
width: 40px;
height: 40px;
border-radius: 50%;
background: linear-gradient(#d1f5ff,#1683ff);
box-shadow: 0 0 30px #1683ff;
}
/* 定義動畫 */
@keyframes animate {
0%{
transform: rotate(0deg);
}
50%,100%{
transform: rotate(360deg);
}
}