Skip to content

Instantly share code, notes, and snippets.

@amatiasq
Last active December 18, 2023 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amatiasq/9db2c21d8cdafb91c79f8d67ca574202 to your computer and use it in GitHub Desktop.
Save amatiasq/9db2c21d8cdafb91c79f8d67ca574202 to your computer and use it in GitHub Desktop.
removeWithTransition.ts
function insertWithTransition(el: HTMLElement, activeClass = 'is-active') {
el.classList.remove(activeClass);
setTimeout(() => {
el.classList.add(activeClass);
}, 0);
}
function removeWithTransition(el: HTMLElement, activeClass = 'is-active') {
const clone = el.cloneNode(true) as HTMLDivElement;
el.parentElement!.insertBefore(clone, el);
clone.addEventListener('transitionend', () => clone.remove());
clone.classList.add(activeClass);
setTimeout(() => {
clone.classList.remove(activeClass);
}, 0);
}
// .my-thing {
// position: fixed;
// inset: 0;
// z-index: 1;
// will-change: top, left, width, height, font-size;
// transition-property: top, left, width, height, font-size;
// transition-timing-function: ease-in-out;
// transition-duration: 200ms;
// }
// .my-thing.is-active {
// top: var(--margin);
// left: var(--margin);
// width: calc(100dvw - var(--margin) * 2);
// height: calc(100dvh - var(--margin) * 2);
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment