webanimations
Animate elements imperatively via the Web Animations API (Element.animate).
Import: @rtorcato/browser-common/webanimations
๐ MDN: Web Animations API ยท ๐ caniuse: web-animation
Browser supportโ
| API | Chrome | Edge | Firefox | Safari | iOS Safari | Baseline |
|---|---|---|---|---|---|---|
Element.animate | โ 36+ | โ 79+ | โ 48+ | โ 13.1+ | โ 13.4+ | Widely available |
โ
supported ยท โ partial ยท โ not supported ยท [n] see note. Generated from MDN browser-compat-data and web-features. caniuse: Element.animate
Exampleโ
import { isWebAnimationsAvailable, animateElement } from '@rtorcato/browser-common/webanimations'
if (isWebAnimationsAvailable()) {
const anim = animateElement(el, [{ opacity: 0 }, { opacity: 1 }], 300)
await anim?.finished
}
Exportsโ
isWebAnimationsAvailable()โ feature checkanimateElement(element, keyframes, options?)โ runselement.animate(); returns theAnimation, ornullif unsupported
See the API reference for full signatures.