Day32精灵动画与多组动画

image
image
精灵动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>精灵动画</title>
    <style>
        .box{
            width: 140px;
            height: 140px;
            border: 1px solid #000;
            background-image: url(./bg.png);
            animation: run 1s steps(12) infinite;
        }

        @keyframes run {
            from{
                background-position: 0 0;
            }
            to{
                background-position: -1680px 0;
            }
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

image

多组动画
image

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>精灵动画</title>
    <style>
        .box{
            width: 140px;
            height: 140px;
            /* border: 1px solid #000; */
            background-image: url(./bg.png);
            animation: 
            run 1s steps(12) infinite,
            move 3s forwards
            ;
        }
        /* 当动画的开始样式和盒子的默认样式相同时,可以省略动画开始状态的代码 */
        @keyframes run {
            /* from{
                background-position: 0 0;
            }*/
            to{
                background-position: -1680px 0;
            }
        }
        @keyframes move {
            /* 0%{
                transform: translate(0);
            }*/
            100%{
                transform: translate(850px);
            } 
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

image

posted @ 2025-12-16 22:28  冰涿  阅读(4)  评论(0)    收藏  举报