08 / 13 ยท CSS
Curtain
A lime curtain rises over the old page. The pages swap behind it, then it lifts away.
The old page leaves, then the new page enters.
let curtain: HTMLElement | null = null
const finished = (element: HTMLElement) => new Promise<void>((resolve) => element.addEventListener('transitionend', () => resolve(), { once: true }))
const hang = (state: string) => {
const element = document.createElement('div')
element.className = 'curtain'
document.body.append(element)
element.getBoundingClientRect()
element.dataset.state = state
return (curtain = element)
}
export const clearCurtain = () => {
curtain?.remove()
curtain = null
}
// out-in, with no animation code at all: the motion is a CSS transition on a data attribute,
// and the transition just waits for it to end.
export const curtainTransition: TransitionHooks = {
mode: 'out-in',
leave: () => finished(hang('covering')),
enter: () => {
const element = curtain ?? hang('covering')
element.dataset.state = 'leaving'
return finished(element).then(clearCurtain)
},
} /* A lime curtain driven by a data attribute. The transition only changes data-state and waits
for the CSS transition to end. */
.curtain {
position: fixed;
inset: 0;
z-index: 60;
background: #e4ff4e;
pointer-events: none;
transform: translateY(100%);
transition: transform 0.6s cubic-bezier(0.65, 0, 0.35, 1);
}
.curtain[data-state="covering"] {
transform: none;
}
.curtain[data-state="leaving"] {
transform: translateY(-100%);
}