Element: getAnimations() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2020.
ThegetAnimations() method of theElement interface(specified on theAnimatable mixin) returns an array of allAnimation objects affecting this element or which are scheduled to do soin future. It can optionally returnAnimation objects for descendantelements too.
Note:This array includesCSS Animations,CSS Transitions, andWeb Animations.
In this article
Syntax
getAnimations()getAnimations(options)Parameters
optionsOptionalAn options object containing the following property:
subtreeA boolean value which, if
true, causes animations that targetdescendants ofElement to be returned as well. This includes animationsthat target any CSSpseudo-elements attached toElement or one of its descendants. Defaults tofalse.
Return value
AnArray ofAnimation objects, each representing ananimation currently targeting theElement on which this method is called,or one of its descendant elements if{ subtree: true } is specified.
Examples
The following code snippet will wait for all animations onelem and itsdescendants to finish before removing the element from the document.
Promise.all( elem.getAnimations({ subtree: true }).map((animation) => animation.finished),).then(() => elem.remove());Specifications
| Specification |
|---|
| Web Animations> # dom-animatable-getanimations> |
Browser compatibility
See also
- Web Animations API
- CSS Animations
- CSS Transitions
Document.getAnimations()- Fetch all animations in the documentAnimation