ShadowRoot: getAnimations() 方法

Baseline 已廣泛支援

此功能已成熟,並可在許多裝置和瀏覽器版本上使用。自 2020 年 9 月起,所有瀏覽器均已提供此功能。

getAnimations() 方法屬於 ShadowRoot 介面,它返回一個數組,其中包含當前生效的所有 Animation 物件,這些物件的 target 元素是 shadow tree 的後代。這個陣列包括 CSS AnimationsCSS TransitionsWeb Animations

語法

js
getAnimations()

引數

無。

返回值

一個 Array,其中包含 Animation 物件,每個物件代表當前與呼叫它的 ShadowRoot 的後代元素相關聯的一個動畫。

示例

以下程式碼片段將透過將其 Animation.playbackRate 減半來減慢 shadow tree 中所有動畫的速度。

js
let customElem = document.querySelector("my-shadow-dom-element");
let shadow = customElem.shadowRoot;
shadow.getAnimations().forEach((animation) => {
  animation.playbackRate *= 0.5;
});

規範

規範
Web 動畫
# dom-documentorshadowroot-getanimations

瀏覽器相容性

另見