css3 animation 中的 steps

steps

Specifies a stepping function, described above, taking two parameters. The first parameter specifies the number of intervals in the function. It must be a positive integer (greater than 0). The second parameter, which is optional, is either the value ‘start’ or ‘end’, and specifies the point at which the change of values occur within the interval. If the second parameter is omitted, it is given the value ‘end’.

粗略翻译如下: steps 函数指定了一个阶跃函数,第一个参数指定了时间函数中的间隔数量(必须是正整数);第二个参数可选,接受 start 和 end 两个值,指定在每个间隔的起点或是终点发生阶跃变化,默认为 end。

这样理解起来可能还是有点抽象,我们来个实例:

#demo {
  animation-iteration-count: 2;
  animation-duration: 3s;
}

这是一个 3s * 2 的动画,我们分别对它应用 steps(3, start) 和 steps(3, end) ,做出阶跃函数曲线如下:

1. steps(3, start)

steps() 第一个参数将动画分割成三段。当指定跃点为 start 时,动画在每个计时周期的起点发生阶跃(即图中 空心圆 → 实心圆 )。 由于第一次阶跃发生在第一个计时周期的起点处(0s),所以我们看到的第一步动画(初态)就为 1/3 的状态,因此在视觉上动画的过程为 1/3 → 2/3 → 1 。如果翻译成 JavaScript,大致如下:

var animateAtStart = function (steps, duration) {
  var current = 0;
  var interval = duration / steps;
  var timer = function () {
    current++;
    applyStylesAtStep(current);
    if (current < steps) {
      setTimeout(timer, interval);
    }
  };
  timer();
};

2. steps(3, end)

当指定跃点为 end,动画则在每个计时周期的终点发生阶跃(即图中 空心圆 → 实心圆 )。 由于第一次阶跃发生在第一个计时周期结束时(1s),所以我们看到的初态为 0% 的状态;而在整个动画周期完成处(3s),虽然发生阶跃跳到了 100% 的状态,但同时动画结束,所以 100% 的状态不可视。因此在视觉上动画的过程为 0 → 1/3 → 2/3 (回忆一下数电里的异步清零,当所有输出端都为高电平的时候触发清零,所以全为高电平是暂态)。同样翻译成 JavaScript 如下:

var animateAtEnd = function (steps, duration) {
  var current = 0;
  var interval = duration / steps;
  var timer = function () {
    applyStylesAtStep(current);
    current++;
    if (current < steps) {
      setTimeout(timer, interval);
    }
  };
  timer();
};

原文地址:https://www.cnblogs.com/jianxian/p/8977785.html

时间: 2024-08-10 18:13:38

css3 animation 中的 steps的相关文章

深入理解CSS3 Animation 帧动画 ( steps )

作者:Aaron的博客 网址:http://www.cnblogs.com/aaronjs/p/4642015.html -------------------------------------------------------------------------------------------------------------------------------- CSS3我在5年之前就有用了,包括公司项目都一直在很前沿的技术. 最近在写慕课网的七夕主题,用了大量的CSS3动画,但是

css3动画中的steps值详解

css3的动画的animation-timing-function属性定义了动画的速度曲线,一般的速度曲线大家都知道,什么ease,linear,ease-in,ease-out,还有自定义贝塞尔曲线...定义了animation-timing-function后,动画就会按照定义的曲线来执行动画. 但是除了这些值以外,animation-timing-function值还可以是steps(x,startend),它接受两个参数.下面会具体解释. 如果定义曲线,则动画帧与帧之间会流畅的进行,而定

CSS3 animation的steps方式过渡

animation默认以ease方式过渡,它会在每个关键帧之间插入补间动画,所以动画效果 是连贯性的.除了ease,linear.cubic-bezier之类的过渡函数都会为其插入补间. 但有些效果不需要补间,只需要关键帧之间的跳跃,这时应该使用steps过渡方式. 比如GIF动图不支持程序对播放的控制,也不支持Alpha通道.但如果我们用一个 PNG图片,把所有帧都放在一起,通过CSS3的animation控制background-position 来播放就可以做到这些. <style> @

css3 animation动画对应属性解释

animation Value:     [<animation-name> || <animation-duration> || <animation-timing-function> || <animation-delay> || <animation-iteration-count> || <animation-direction> || <animation-fill-mode>] [, [<animatio

css3 animation 属性众妙

转自:凹凸实验室(https://aotu.io/notes/2016/11/28/css3-animation-properties/) 本文不会详细介绍每个 css3 animation 属性(需要了解的同学可先移步 MDN),而是结合实际的开发经验,介绍 css3 animation 属性的一些使用场景及技巧. 1. animation-delay MDN 中的介绍: animation-delay CSS 属性定义动画于何时开始,即从动画应用在元素上到动画开始的这段时间的长度. 该属性值

CSS3 transition动画、CSS3 transform变换、CSS3 animation动画

CSS3 transition动画 1.transition-property 设置过渡的属性,比如:width height background-color2.transition-duration 设置过渡的时间,比如:1s 500ms3.transition-timing-function 设置过渡的运动方式 linear 匀速 ease 开始和结束慢速 ease-in 开始是慢速 ease-out 结束时慢速 ease-in-out 开始和结束时慢速 cubic-bezier(n,n,

CSS3 Animation

animation:[<animation-name> || <animation-duration> || <animation-timing-function> || <animation-delay> || <animation-iteration-count> || <animation-direction>] [, [<animation-name> || <animation-duration> |

HTML 学习笔记 CSS3(Animation)

CSS3动画: 通过CSS3 我们能够创建动画 这可以在许多网页中取代动画图片 Flash动画 以及JavaScript. CSS3 @keyframes 规则如需在 CSS3 中创建动画,您需要学习 @keyframes 规则.@keyframes 规则用于创建动画.在 @keyframes 中规定某项 CSS 样式,就能创建由当前样式逐渐改为新样式的动画效果. 同样的先看一个例子: <html> <head> <meta charset="UTF-8"

实现了一个百度首页的彩蛋——CSS3 Animation简介

在百度搜索中有这样一个彩蛋:搜索“旋转”,“跳跃”,“反转”等词语,会出现相应的动画效果(搜索“反转”后的效果).查看源码可以发现,这些效果正是通过CSS3的animation属性实现的. 实现这个彩蛋 简单来说可以分三步: 1.实现一些css动画类,等待调用: 2.设立关键字与动画匹配方法: 3.每当页面加载完成,根据关键字为body添加指定动画类. 查看DEMO:百度搜索彩蛋 CSS3 Animation animation: name duration timing-function de