類似液體loading效果

直接上代碼,有註釋
index.html

<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>水波紋loading</title>
    <style>
        html {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            margin: 0;
            padding: 0;
            /*這三句讓彈性盒子內容絕對居中*/
            display: flex;
            justify-content: center;
            align-items: center;

            height: 100vh;
            background-color: #222;
        }

        /*不讓svg佔據盒子空間*/
        svg {
            width: 0;
            height: 0;
        }

        .loader {
            position: relative;
            /*border: 1px solid silver;*/
            width: 200px;
            height: 200px;
            /*URL函數接受一個XML文件,該文件設置了 一個SVG濾鏡,且可以包含一個錨點來指定一個具體的濾鏡元素。
            這裏是 filter: url(svg-url#element-id)*/
            filter: url(#gooey);
        }

        .loader > span {
            position: absolute;
            display: block;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            /*background-color: #fff;*/
            animation: loader 4s ease-in-out infinite;
            /*動畫延時:這裏給calc計算屬性,每個span延時*/
            animation-delay: calc(0.2s * var(--i));
        }

        .loader > span:before {
            content: '';
            position: absolute;
            display: block;
            top: 0;
            width: 40px;
            height: 40px;
            /*這兩句讓元素水平居中*/
            left: 50%;
            transform: translateX(-50%);
            /*圓*/
            border-radius: 50%;
            box-shadow: 0 0 30px #03a9f4;
            background-image: linear-gradient(#fce4ec, #03a9f4);
        }
        /*所有的span盒子進行該動畫*/
        @keyframes loader {
            0% {
                transform: rotate(0deg);
            }
            50%, 100% {
                transform: rotate(360deg);
            }
        }

    </style>
</head>
<body>
<div class="loader">
    <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 id="gooey">
        <feGaussianBlur in="SourceGraphic" stdDeviation="10"></feGaussianBlur>
        <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>

效果圖
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章