Animation.Animation()

Baseline 2022

Newly available

Since September 2022, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

Animation 构造函数返回一个新的 Animation 对象实例。

语法

js
var animation = new Animation(effect, timeline);

参数

effect 可选

KeyframeEffect (en-US)对象分配给动画。(在将来,其他类型的效果,如 SequenceEffects 或 GroupEffects 是可能被实现的,但现在,唯一的效果是 KeyframeEffect。)

timeline 可选

指定与动画关联的时间轴。(目前唯一可用的时间轴类型是DocumentTimeline (en-US),但在将来我会有与手势或滚动相关联的时间轴。)默认为Document.timeline。这也可以设置为 null。

例子

White Rabbit示例中,Animation 构造函数用于使用文档时间轴为兔子创建关键帧动画:

js
var rabbitDownAnimation = new Animation(rabbitDownKeyframes, document.timeline);

规范

Specification
Web Animations
# dom-animation-animation

浏览器兼容性

BCD tables only load in the browser

参见