Element: getAnimations() メソッド
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2020年7月.
getAnimations() は Element インターフェイスのメソッドで(Animatable ミックスインで指定されており)、この要素に影響を与える、あるいは将来的に影響を与える予定のすべての Animation オブジェクトの配列を返します。オプションとして、子孫要素の Animation オブジェクトも返すことができます。
メモ: この配列には CSS アニメーション、CSS トランジション、ウェブアニメーションが含まれます。
構文
js
getAnimations()
getAnimations(options)
引数
options省略可-
以下のプロパティを含むオプションオブジェクトです。
返値
Animation オブジェクトの配列 (Array) で、それぞれが
このメソッドが呼び出された Element、または { subtree: true } が指定されている場合は、その子孫の要素の 1 つを現在ターゲットにしているアニメーションです。
例
以下のコードでは、 elem とその子孫のすべてのアニメーションが終了するのを待ってから、文書からその要素を削除します。
js
Promise.all(
elem.getAnimations({ subtree: true }).map((animation) => animation.finished),
).then(() => elem.remove());
仕様書
| Specification |
|---|
| Web Animations> # dom-animatable-getanimations> |
ブラウザーの互換性
Loading…
関連情報
- ウェブアニメーション API
- CSS アニメーション
- CSS トランジション
Document.getAnimations()- 文書内のすべてのアニメーションを読み取るAnimation