ShadowRoot: getAnimations() 方法
getAnimations() 方法屬於 ShadowRoot 介面,它返回一個數組,其中包含當前生效的所有 Animation 物件,這些物件的 target 元素是 shadow tree 的後代。這個陣列包括 CSS Animations、CSS Transitions 和 Web 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 |
瀏覽器相容性
載入中…
另見
- Web Animations API
- CSS 動畫
- CSS 過渡
Element.getAnimations()- 僅獲取單個Element及其後代上的動畫。Animation