使用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>
相关推荐
FreeTinker23 分钟前
HTML本地存储技术解析:localStorage与sessionStorage的原理、差异与应用场景
前端·html
qq_4523962324 分钟前
第十二篇:《全链路监控与可观测性:前端错误追踪与性能分析》
前端
wangruofeng1 小时前
Phosphor Icons 官网源码拆解:URL 即存储、水波动画与 7362 Star 图标库的架构实践
前端·架构·github
BigTopOne2 小时前
WebRTC Native / Android 开发学习资源整理
前端
excel3 小时前
nuxt 3 升级 nuxt 4 报错之 hasInjectionContext
前端
何以解忧,唯有..3 小时前
LangChain 工具调用(Tool Calling)实战指南
java·前端·langchain
软件聚导航4 小时前
「聚小软 AI 助手」技术升级:从数据库检索到 RAG 知识库问答
前端·数据库·mysql·微信小程序·小程序·ai编程·rag
恋猫de小郭4 小时前
看懂大模型架构术语,帮助你理解目前常见的大模型开源架构
前端·人工智能·ai编程
yma164 小时前
通过提示词实现GitHub Pages 和 Nginx 双部署竟然这么简单?
前端
前端 贾公子5 小时前
第09章:上下文与记忆 (2)
java·服务器·前端