Element
的 animate()
方法是在 JS 侧给 UI 元件设置 CSS Animation 动画的快捷方法。
id
查找需要做动画的 Element
对象。Element
对象上的 animate
API 实现动画。有两种不同的格式:
Animate API 也支持 Segment Timing Function,因此你也可以在 Animate API 中为每段 Keyframe 单独指定 Timing Function。
包含一个或多个属性的对象:
Key | Value类型 | 是否可选 | 说明 | 默认值 |
---|---|---|---|---|
duration | Number | optional | 动画持续时间 | 0 |
delay | Number | optional | 动画开始生效前的延迟时间 | 0 |
iterations | Number | optional | 动画的重复次数。可以将其设为Infinity令动画无限循环。 | 1 |
direction | String | optional | Whether the animation runs forwards (normal ), backwards (reverse ), switches direction after each iteration (alternate ), or runs backwards and switches direction after each iteration (alternate-reverse ). Defaults to "normal" . | "normal" |
easing | String | optional | 动画的时间函数,表示动画在时间上的变化速率。接受一个timing-function,例如"linear" , "ease-in" , "step-end" , or "cubic-bezier(0.42, 0, 0.58, 1)" 。 | "linear" |
fill | String | optional | 表示动画在执行之前和之后如何将样式应用于其目标,接受一个animation-fill-mode,例如"backwards" ,"forwards" ,"both" 。 | "none" |
name | String | optional | 动画的名字,可作为动画的唯一标识。该名字会出现在动画事件参数中,通常用于判断某个动画事件是否是你想要的。 | 内部的unique ID |
play-state | String | optional | 动画的运动状态,定义一个动画是否运行或者暂停,接受一个animation-play-state | running |
返回 Animation
对象。
Animation
对象上的方法:
方法名 | 说明 |
---|---|
Animation.cancel() | 取消动画的执行,会触发animation cancel事件。 |
Animation.pause() | 暂停动画的执行。 |
Animation.play() | 恢复动画的执行。 |
Animate API 的事件和 CSS Animation 动画事件相同。
Animate API 与 CSS Animation 会互相覆盖,后生效的那一方会覆盖前者。
每次调用 lynx.getElementById("test").animate
都会生成一个新的 Animation
对象。
Animate Api 暂只支持创建一个动画,未来会支持创建多个。因此现在若对一个节点多次调用 lynx.getElementById("test").animate
,最后创建的动画会覆盖前面的动画。
一个 Animation
对象对应的动画结束后,若想重启一个同样的动画,需要重新调用 lynx.getElementById("test").animate
创建一个新的 Animation
对象。
Animate API 暂只支持 getElementById API,对 SelectQuery API 的支持还未接入。
Animate API 不生效,可能是 getElementById 未能选中节点:
LCD tables only load in the browser