前端 - css3动画怎样对帧的理解?
问题描述
第一种:
@keyframes slow {0% { background-position: -0px -291px;}25% { background-position: -602px -0px;}50% { background-position: -302px -291px;}75% { background-position: -151px -291px;}100% { background-position: -0px -291px;} } /*动画切换的方式是一帧一帧的改变*/-webkit-animation-timing-function: steps(1, start);
第二种:
$spriteWidth: 140px; // 精灵宽度 @keyframes run { 0% { background-position: 0 0; } 100% { background-position: -($spriteWidth * 12) 0; // 12帧 }}#sprite { width: $spriteWidth; height: 144px; background: url('../images/sprite.png') 0 0 no-repeat; animation: run 0.6s steps(12) infinite;}
1,什么叫“一帧一帧的改变”, steps(1, start);该如何理解?2,第二种直接“-($spriteWidth * 12) 0”我就看不懂了,为什么这样写?
问题解答
回答1:1. 什么叫“一帧一帧的改变”, steps(1, start);该如何理解?animation-timing-function 中 steps 的用法参见这篇
steps 详解
2. 第二种直接“-($spriteWidth * 12) 0”我就看不懂了,为什么这样写?首先显然这是 Scss 文件(一种 css 预编译文件)
定义了一个变量:$spriteWidth
-($spriteWidth * 12) 这句就是一个运算呀 => -(140px*12)
回答2:1: steps(1, start)我在MDN上刚好看到一个解释
This keyword represents the timing function steps(1, start). Using this timing function, the animation jumps immediately to the end state and stay in that position until the end of the animation.
就是说你的动画帧一开始就马上跳到结束了,所以你看见的是keyframes里面5个帧一帧一帧地切换。如果没有steps(1, start),就会是一个平滑移动的效果。
2: -($spriteWidth * 12)应该是指把你这个动画分成12帧,每一帧你的背景右移-($spriteWidth * 12)这个长度
相关文章:
1. css - chrome浏览器input记录上次cookie信息后,有个黄色背景~如何去除!2. 请教,关于python字典,合并相同值的键的实现方法3. javascript - 如何将 windows 下编辑器中的 CRLF 替换为 LF?4. android - 京东移动端网页和其app加载的url所做的呈现不应该是完全一样的吗?5. mysql5.7就没有官方性质的详细配置文件吗?求大神告知6. Windows系统能否利用Docker使用Ubuntu吗?Ubuntu能使用本机的显卡吗?7. javascript - 求解答:实例对象调用constructor,此时constructor内的this的指向?8. html5 - 在一个页面中 初始了两个swiper 不知道哪里错了 一直不对9. css3中translate(-50%,-50%)对 transform-origin的奇葩影响?10. python的MySQLdb库中的executemany方法如何改变默认加上的单引号?

网公网安备