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

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

图片和代码文件点击获取

相关推荐
Stringzhua8 小时前
Vue中的数据渲染【4】
css·vue.js·css3
郭优秀的笔记2 天前
抽奖程序web程序
前端·css·css3
xixixin_3 天前
【HTML】在页面中画一条0.5px的线
前端·css·uni-app·html·css3
chinahcp20084 天前
CSS保持元素宽高比,固定元素宽高比
前端·css·html·css3·html5
暖木生晖4 天前
flex-wrap子元素是否换行
javascript·css·css3·flex
未来之窗软件服务4 天前
企业收款统计:驱动业务决策的核心引擎设计开发——仙盟创梦IDE
javascript·css3·仙盟创梦ide·东方仙盟·企业收款码
艾小码4 天前
HTML5 & CSS3 从入门到精通:构建现代Web的艺术与科学
前端·css3·html5
芜青5 天前
实现文字在块元素中水平/垂直居中详解
前端·css·css3
枫叶是圆的5 天前
纯CSS+JS制作抽奖大转盘
前端·javascript·css·html·css3
Darling02zjh5 天前
_CSS3
前端·css·css3