逐帧动画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) 是一种特定的时间函数,它表示动画将在每个关键帧之间离散地切换,就像一步一步前进一样。

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

图片和代码文件点击获取

相关推荐
ヤ鬧鬧o.4 小时前
HTML安全密码备忘录
前端·javascript·css·html·css3
光影少年14 小时前
flex布局和grid布局区别,实现两边固定布局中间自适应
前端·css3·web·ai编程
Ulyanov1 天前
Impress.js深度解析
开发语言·前端·javascript·css3·impress.js
苯酸氨酰糖化物1 天前
HTML+CSS学信网学籍学历查询页面-支持任意修改内容信息
前端·css3·html5·娱乐
Southern Wind1 天前
从零开始封装一个优雅的图片上传组件 - 二次改装 Layui-Upload 的教程(附完整封装代码)
前端·javascript·html·layui·css3
米奇妙妙wuu3 天前
css实现文字和边框同样的渐变色效果
css·html·css3
我是伪码农5 天前
轮播图案例
css·html·css3
符文师5 天前
css3 新特性
前端·css3
n 55!w !1085 天前
静态网页作业
前端·css·css3
鸢尾掠地平6 天前
如何制作一个简单的学习教务系统?
css·学习·css3