Animation.id

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.

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

Web Animations APIAnimation.id 属性可返回或设置用于识别某个动画的唯一标识。

获取与设置 animation.id

js
// 获取动画的 id
var animationsId = animation.id;

// 设置动画的 id
animation.id = "newId";

返回值

当该动画已被分配 id,返回一个 DOMString, 当该动画未被分配 id 则返回 null.

示例

Follow the White Rabbit example 这个例子里,你可以像下面的方式一样,为 rabbitDownAnimation 分配一个 id:

js
rabbitDownAnimation.effect.id = "rabbitGo";

规范

Specification
Web Animations
# dom-animation-id

浏览器兼容性

BCD tables only load in the browser

参见