css实现一个炫酷动画loading(一)


html

typescript 复制代码
   <div class="loader">
        <div class="circle">
            <div class="dot"></div>
            <div class="outline"></div>
        </div>
        <div class="circle">
            <div class="dot"></div>
            <div class="outline"></div>
        </div>
        <div class="circle">
            <div class="dot"></div>
            <div class="outline"></div>
        </div>
        <div class="circle">
            <div class="dot"></div>
            <div class="outline"></div>
        </div>
    </div>

css

typescript 复制代码
<style>
    body {
        background-color: #000;
    }
    .loader {
        margin-top: 200px;
        display: flex;
        justify-content: center;
        align-items: center;
        --color: hsl(0, 0%, 87%);
        --animation: 2s ease-in-out infinite;
    }

    .loader .circle {
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        width: 20px;
        height: 20px;
        border: solid 2px var(--color);
        border-radius: 50%;
        margin: 0 10px;
        background-color: transparent;
        animation: circle-keys var(--animation);
    }

    .loader .circle .dot {
        position: absolute;
        transform: translate(-50%, -50%);
        width: 16px;
        height: 16px;
        border-radius: 50%;
        background-color: var(--color);
        animation: dot-keys var(--animation);
    }

    .loader .circle .outline {
        position: absolute;
        transform: translate(-50%, -50%);
        width: 20px;
        height: 20px;
        border-radius: 50%;
        animation: outline-keys var(--animation);
    }

    .circle:nth-child(2) {
        animation-delay: 0.3s;
    }

    .circle:nth-child(3) {
        animation-delay: 0.6s;
    }

    .circle:nth-child(4) {
        animation-delay: 0.9s;
    }

    .circle:nth-child(5) {
        animation-delay: 1.2s;
    }

    .circle:nth-child(2) .dot {
        animation-delay: 0.3s;
    }

    .circle:nth-child(3) .dot {
        animation-delay: 0.6s;
    }

    .circle:nth-child(4) .dot {
        animation-delay: 0.9s;
    }

    .circle:nth-child(5) .dot {
        animation-delay: 1.2s;
    }

    .circle:nth-child(1) .outline {
        animation-delay: 0.9s;
    }

    .circle:nth-child(2) .outline {
        animation-delay: 1.2s;
    }

    .circle:nth-child(3) .outline {
        animation-delay: 1.5s;
    }

    .circle:nth-child(4) .outline {
        animation-delay: 1.8s;
    }

    .circle:nth-child(5) .outline {
        animation-delay: 2.1s;
    }

    @keyframes circle-keys {
        0% {
            transform: scale(1);
            opacity: 1;
        }

        50% {
            transform: scale(1.5);
            opacity: 0.5;
        }

        100% {
            transform: scale(1);
            opacity: 1;
        }
    }

    @keyframes dot-keys {
        0% {
            transform: scale(1);
        }

        50% {
            transform: scale(0);
        }

        100% {
            transform: scale(1);
        }
    }

    @keyframes outline-keys {
        0% {
            transform: scale(0);
            outline: solid 20px var(--color);
            outline-offset: 0;
            opacity: 1;
        }

        100% {
            transform: scale(1);
            outline: solid 0 transparent;
            outline-offset: 20px;
            opacity: 0;
        }
    }
</style>
相关推荐
高山我梦口香糖1 小时前
[react]searchParams转普通对象
开发语言·前端·javascript
唯之为之1 小时前
巧用mask属性创建一个纯CSS图标库
css·svg
m0_748235241 小时前
前端实现获取后端返回的文件流并下载
前端·状态模式
m0_748240252 小时前
前端如何检测用户登录状态是否过期
前端
black^sugar2 小时前
纯前端实现更新检测
开发语言·前端·javascript
寻找沙漠的人3 小时前
前端知识补充—CSS
前端·css
GISer_Jing3 小时前
2025前端面试热门题目——计算机网络篇
前端·计算机网络·面试
m0_748245523 小时前
吉利前端、AI面试
前端·面试·职场和发展
理想不理想v3 小时前
webpack最基础的配置
前端·webpack·node.js