逐帧动画demo


用这一张图实现一个在跑的猎豹的动画

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .container{
            width: 100px;
            height: 100px;
            border: 1px solid red;
            background: url(./animal.png) no-repeat;
            animation: run 1s infinite;
            animation-timing-function: steps(1);
            /* steps(1) 是一种特定的时间函数,它表示动画将在每个关键帧之间离散地切换,就像一步一步前进一样。 */
            /* 动画会在每个关键帧之间立即切换,而不会经过过渡动画 */
        }
        @keyframes run{
            0%{
                background-position: 0 0;
            }
            12.5%{
                background-position: -100px 0;
            }
            25%{
                background-position: -200px 0;
            }
            37.5%{
                background-position: -300px 0;
            }
            50%{
                background-position: 0 -100px;
            }
            62.5%{
                background-position: -100px -100px;
            }
            75%{
                background-position: -200px -100px;
            }
            87.5%{
                background-position: -300px -100px;
            }
            100%{
                background-position: 0 0;
            }
        }
    </style>
</head>
<body>
    <div class="container">
    </div>
</body>
</html>

steps(1) 是一种特定的时间函数,它表示动画将在每个关键帧之间离散地切换,就像一步一步前进一样。

动画会在每个关键帧之间立即切换,而不会经过过渡动画

图片和代码文件点击获取

相关推荐
小九今天不码代码9 天前
CSS 九宫格拼图动画效果实现与原理解析
css·css3·动画效果·css动画·grid布局·css技巧·九宫格布局
QmZVLlLHvXq18 天前
汇川多合一上位机软件 支持宇通,东风凯普特,陕汽德龙等多车型 支持数据读取,修改,故障码读取
css3
程序员林北北20 天前
【前端进阶之旅】3 道前端超难面试题深度解析(2026 版)|附完整代码 + 实战场景
前端·javascript·css3·html5
Kyl2n21 天前
【密码口令保存小工具】
javascript·css·css3
银烛木21 天前
黑马程序员前端h5+css3
前端·css·css3
m0_6070766021 天前
CSS3 转换,快手前端面试经验,隔壁都馋哭了
前端·面试·css3
听海边涛声21 天前
CSS3 图片模糊处理
前端·css·css3
IT、木易21 天前
css3 backdrop-filter 在移动端 Safari 上导致渲染性能急剧下降的优化方案有哪些?
前端·css3·safari
henry10101022 天前
DeepSeek生成的网页小游戏 - 迷宫探险
css·游戏·html·css3
cvcode_study23 天前
PHP8 编程入门课程
开发语言·javascript·php·css3·html5