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

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

图片和代码文件点击获取

相关推荐
志尊宝6 天前
Vue3 环境搭建 + 第一个 HelloVue 项目(零基础入门)
vue.js·node.js·vue·css3
More more6 天前
纯手搓css样式:科技感弹窗边框
css·科技·css3
丨我是张先生丨7 天前
英语单词 Web Page
前端·css·css3
丨我是张先生丨9 天前
日语单词 Web Page
前端·css·css3
AI视觉网奇1 个月前
three教学 3d资产拼接源代码
前端·css·css3
神明不懂浪漫1 个月前
【第三章】CSS(一)——基础选择器、CSS的属性
前端·css·html·css3
智码看视界1 个月前
老梁聊全栈:CSS3 高级特性—Flex/Grid 布局体系深度解析
前端·css3·布局·flexbox·grid·工程实践·全栈工程师
gz-郭小敏1 个月前
优化横向滚动展示大量数据的时候数据晃动问题
前端·javascript·html·css3
贩卖黄昏的熊1 个月前
flex 布局快速梳理
开发语言·javascript·css3·html5
川冰ICE1 个月前
JavaScript实战④|天气查询应用,调用API与异步处理
javascript·css·css3