Loading文字扫描

html中写入Loading文字内容:

新建html文件,在body中放入Loading文字内容

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Loading文字扫描加载</title>
</head>
<body>
    <h1>Loading...</h1>
</body>
</html>

设置CSS样式

设置网页样式,整体内容居中,设置背景颜色

/* 设置全局属性的内外边距为0,盒子大小包括内外边距 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

/* 设置文档主体的样式,弹性盒子,内容水平居中,垂直居中 */
body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #252839;
}

设置文本样式,设置字体颜色与底色相同,添加文字描边效果,模拟镂空效果

/* 设置文本的样式 */
h1 {
    position: relative;
    /* 调整字体颜色,根据屏幕自适应 */
    font-size: 14vw;
    /* 设置字体颜色与底色相同,添加文字描边效果,模拟镂空效果 */
    color: #252839;
    -webkit-text-stroke: 0.3vw #383d52;
}

添加伪元素

使用CSS添加伪元素,并在Loading文字上层显示

/* 定位伪元素,显示上层内容 */
h1::before {
    content: 'Loading...';
    /* 设置伪元素的位置在文字上面 */
    position: absolute;
    left: 0;
    top: 0;
    width: 0%;
    height: 100%;
    color: #01fe87;
    /* 默认遮盖元素宽度0%,溢出后隐藏 */
    overflow: hidden;
    -webkit-text-stroke: 0vw #383d52;
    /* 伪元素有边框,模拟扫描竖杠 */
    border-right: 2px solid #01fe87;
}

设置动画效果

使用@Keyframes 定义动画效果

@keyframes animate {
    0% {
        width: 0%;
    }
    90% {
        width: 100%;
    }
    100% {
        width: 100%;
    }
}

伪元素中使用动画

h1::before {
    /* 使用动画 参数:动画名称、动画完成时间、动画的展示过程(线性)播放次数 下一周期是否逆向播放 */
    animation: animate 5s linear infinite alternate;
}

代码展示与运行效果

完整代码展示

<!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>
        /* 设置全局属性的内外边距为0,盒子大小包括内外边距 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Poppins', sans-serif;
        }

        /* 设置文档主体的样式,弹性盒子,内容水平居中,垂直居中 */
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-color: #252839;
        }

        /* 设置文本的样式 */
        h1 {
            position: relative;
            /* 调整字体颜色,根据屏幕自适应 */
            font-size: 14vw;
            /* 设置字体颜色与底色相同,添加文字描边效果,模拟镂空效果 */
            color: #252839;
            -webkit-text-stroke: 0.3vw #383d52;
        }

        /* 定位伪元素,显示上层内容 */
        h1::before {
            content: 'Loading...';
            /* 设置伪元素的位置在文字上面 */
            position: absolute;
            left: 0;
            top: 0;
            width: 0%;
            height: 100%;
            color: #01fe87;
            /* 默认遮盖元素宽度0%,溢出后隐藏 */
            overflow: hidden;
            -webkit-text-stroke: 0vw #383d52;
            /* 伪元素有边框,模拟扫描竖杠 */
            border-right: 2px solid #01fe87;
            /* 使用动画 参数:动画名称、动画完成时间、动画的展示过程(线性)播放次数 下一周期是否逆向播放 */
            animation: animate 5s linear infinite alternate;
        }

        @keyframes animate {
            0% {
                width: 0%;
            }
            90% {
                width: 100%;
            }
            100% {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <h1>Loading...</h1>
</body>
</html>

运行结果展示

Reference:听说过css技术

不足之处,请多多指教!!!

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值