使用css实现动态loading

效果图

关键样式 - 遮罩mask

www.w3school.com.cn/css/css3_ma...

图片素材

【注】需要透明底色的文字图片

完整代码

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>loading</title>
    <style lang="scss" scoped>
        * {
            padding: 0;
            margin: 0;
        }

        .a-loading {
            width: 100vw;
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .content {
            position: absolute;
            padding: 0 20px;
            border-radius: 20px;
            background-color: #dad8d554;

        }

        .content-loading {
            max-width: 420px;
            min-width: 300px;
            width: 100%;
            height: 90px;
            background: linear-gradient(to right, #ffffff, #d94c4c);
            background-size: 200%;
            animation: translationX 2s linear infinite;
            /* mask-size: 100%; */
            mask-repeat: no-repeat;
            mask-position: center;
            mask-image: url("/images/loading1.png");
        }

        @keyframes translationX {
            0% {
                background-position: 200% 200%;
            }

            100% {
                background-position: 0 0;
            }
        }
    </style>
</head>

<body>
    <div class="a-loading">
        <div class="content">
            <div class="content-loading"> </div>
        </div>
    </div>
</body>

</html>
相关推荐
程序员黑豆6 分钟前
鸿蒙应用开发:AppStorage 全局状态存储用法教程
前端·harmonyos
猫猫不是喵喵.14 分钟前
Vue3 中 computed 计算属性与 watch、watchEffect 监听
前端·javascript·vue.js
En^_^Joy26 分钟前
Vue项目创建与入口配置全攻略
前端·vue.js·arcgis
爱码小白1 小时前
importlib模块
开发语言·前端·python
猫猫不是喵喵.1 小时前
Vue2 的 Vuex 状态管理与 Vue3 的 Pinia 状态管理
前端·javascript·vue.js
greenbbLV1 小时前
中小公司积分商城选型:SaaS与私有化方案对比解析
大数据·前端·小程序
NutShell Wang3 小时前
Vite 8.1 深度拆解:Rolldown 统一打包器如何终结前端构建的「双引擎时代」
前端·rust·开源·vite·开发者工具·vibe coding
朱容zr3331333 小时前
请解释“回表”的概念。
java·前端·数据库
软件技术NINI3 小时前
盗墓笔记html+css+js 2页
css·笔记·html
leslie1183 小时前
webpack笔记
前端·webpack