09 / 13 ยท GSAP
Bars
Lime bars cover the old page, staggered. The pages swap behind them, then the bars drop away.
The old page leaves, then the new page enters.
let overlay: HTMLElement | null = null
const build = (): HTMLElement => {
const element = document.createElement('div')
Object.assign(element.style, { position: 'fixed', inset: '0', zIndex: '60', display: 'flex', pointerEvents: 'none' })
for (let i = 0; i < 6; i++) {
const bar = document.createElement('div')
Object.assign(bar.style, { flex: '1', marginRight: '-1px', background: '#e4ff4e', transform: 'scaleY(0)' })
element.append(bar)
}
document.body.append(element)
return (overlay = element)
}
export const clearBars = () => {
overlay?.remove()
overlay = null
}
// out-in, written with GSAP, loaded only when this transition first runs. Chasse works the same
// with any library, or none: GSAP is just one of the options. Here it earns its place with stagger.
export const bars: TransitionHooks = {
mode: 'out-in',
leave: async () => {
const { gsap } = await import('gsap')
await gsap.to(build().children, { scaleY: 1, transformOrigin: 'bottom', duration: 0.5, ease: 'power3.inOut', stagger: 0.06 })
},
enter: async () => {
const { gsap } = await import('gsap')
const bars = (overlay ?? build()).children
gsap.set(bars, { scaleY: 1, transformOrigin: 'top' })
await gsap.to(bars, { scaleY: 0, duration: 0.5, ease: 'power3.inOut', stagger: 0.06 })
clearBars()
},
}