CSS动画实现进度条从左到右滚动

时间:2022-01-06 来源:未知网络 作者:996建站网

很简单,上代码。


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>animation</title>
    <style>
        .rec {
            box-sizing: border-box;
            position: relative;
            overflow: hidden;
            margin: 300px auto;
            width: 300px;
            height: 4px;
            border: 1px solid #ccc;
        }
        .rec::before {
            position: absolute;
            left: -100%;
            top: 0;
            content: '';
            height: 2px;
            width: 298px;
            background-color: red;
            /* 依次对应:动画名、时长、匀速、无限循环 */
            animation: move 10s linear infinite; 
        }

        @keyframes move {
            from {
                left: -100%;
            }
            to {
                left: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="rec"></div>
</body>
</html>

CSS动画实现进度条从左到右滚动插图

微信扫一扫 关注公众号

微信扫一扫 使用小程序

百度扫一扫 使用小程序