Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Last active July 19, 2024 13:59
Show Gist options
  • Save jakearchibald/0b50c4918eaf9a67bfcfa55e7e61cd56 to your computer and use it in GitHub Desktop.
Save jakearchibald/0b50c4918eaf9a67bfcfa55e7e61cd56 to your computer and use it in GitHub Desktop.
/**
* @param {HTMLElement} element
* @param {Keyframe[] | PropertyIndexedKeyframes} to
* @param {KeyframeAnimationOptions} options
*/
export function animateTo(element, to, options) {
const anim = element.animate(
to,
{ ...options, fill: 'both' },
);
anim.addEventListener('finish', () => {
anim.commitStyles();
anim.cancel();
});
return anim;
}
/**
* @param {HTMLElement} element
* @param {PropertyIndexedKeyframes} from
* @param {KeyframeAnimationOptions} options
*/
export function animateFrom(element, from, options) {
return element.animate(
{ ...from, offset: 0 },
{ ...options, fill: 'backwards' },
);
}
@aryanpingle
Copy link

I see, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment