@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
24 lines (20 loc) • 651 B
JavaScript
/*!
* @techmely/utils
* Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com>
* MIT Licensed
*/
// src/stopAnimation.ts
function stopAnimations(el) {
return Promise.all(
el.getAnimations().map((animation) => {
return new Promise((resolve) => {
const handleAnimationEvent = requestAnimationFrame(resolve);
animation.addEventListener("cancel", () => handleAnimationEvent, { once: true });
animation.addEventListener("finish", () => handleAnimationEvent, { once: true });
animation.cancel();
cancelAnimationFrame(handleAnimationEvent);
});
})
);
}
export { stopAnimations };