Chasse.

02 / 13 ยท Web Animations API

Slide

Both pages move together. It is also what a swipe scrubs, so try dragging on a phone.

Both pages are on screen and animate together.

The transition
// sync: both pages move together. Going back mirrors it. A drag scrubs these animations,
// so they ease linearly when a gesture started the visit.
const ease = 'cubic-bezier(0.65, 0, 0.35, 1)'

export const slide: TransitionHooks = {
  mode: 'sync',
  leave: ({ current, direction, gesture }) =>
    current.animate(
      { transform: ['none', `translateX(${direction === 'back' ? 30 : -30}%)`], opacity: [1, 0.3] },
      { duration: 800, easing: gesture ? 'linear' : ease, fill: 'forwards' },
    ),
  enter: ({ next, direction, gesture }) =>
    next.animate(
      { transform: [`translateX(${direction === 'back' ? -100 : 100}%)`, 'none'] },
      { duration: 800, easing: gesture ? 'linear' : ease },
    ),
}