Docs
Docs
Enough to get a first transition running. The full guide and API reference are in the README on npm.
Install
npm install @studio-lumio/chasse Or load it from a script tag, which exposes a Chasse global.
<script src="https://cdn.jsdelivr.net/npm/@studio-lumio/chasse@0.6"></script> Quick start
Mark the part of the page that changes. Everything outside it, like a header, stays on screen between pages.
<main data-chasse-container>
<!-- this page's content -->
</main> Then create the router with a transition. This one uses the Web Animations API, which every browser has, so there is nothing else to install.
import { createRouter } from '@studio-lumio/chasse'
createRouter({
transition: () => 'fade',
transitions: {
fade: {
mode: 'out-in',
leave: ({ current }) =>
current.animate({ opacity: [1, 0] }, { duration: 350, fill: 'forwards' }),
enter: ({ next }) => next.animate({ opacity: [0, 1] }, { duration: 450 }),
},
},
}) Any animation tool
Chasse doesn't animate anything itself. A transition returns whatever does, and Chasse waits for it to finish. It takes a Web Animation, a GSAP timeline or tween, a promise, or nothing. Here is the same fade written four ways. The samples run each of them.
const fade = {
mode: 'out-in',
leave: ({ current }) =>
current.animate({ opacity: [1, 0] }, { duration: 350, fill: 'forwards' }),
enter: ({ next }) => next.animate({ opacity: [0, 1] }, { duration: 450 }),
} [data-chasse-container].is-leaving { opacity: 0; transition: opacity 0.35s; }
@keyframes page-in { from { opacity: 0; } }
[data-chasse-container].is-entering { animation: page-in 0.45s; } const ended = (element, type) =>
new Promise((resolve) => element.addEventListener(type, resolve, { once: true }))
const fade = {
mode: 'out-in',
leave: ({ current }) => {
current.classList.add('is-leaving')
return ended(current, 'transitionend')
},
enter: ({ next }) => {
next.classList.add('is-entering')
return ended(next, 'animationend')
},
} import { gsap } from 'gsap'
const fade = {
mode: 'out-in',
leave: ({ current }) => gsap.to(current, { opacity: 0, duration: 0.35 }),
enter: ({ next }) =>
gsap.fromTo(next, { opacity: 0 }, { opacity: 1, duration: 0.45, clearProps: 'opacity' }),
} import { native } from './native' // the helper below
// Add nothing else: the browser cross-fades the two snapshots by default.
const fade = native('fade') The View Transitions helper
interface NativeOptions {
/** Runs before the old page is captured: name elements that should morph, set variables for the CSS. */
before?: (visit: Visit) => void
/** Runs once the new page is in, just before it is captured. */
after?: (visit: Visit) => void
/** Runs when the transition is over or was cancelled. */
done?: () => void
}
// out-in, with the swap held by the browser's View Transitions API. `leave` starts the
// transition: the browser captures the old page and keeps showing it while Chasse fetches and
// swaps the pages. `enter` lets the browser capture the new page, then CSS animates the two.
export const native = (name: string, { before, after, done }: NativeOptions = {}): TransitionHooks => {
let swapped: (() => void) | null = null
let transition: ViewTransition | null = null
const reset = () => {
const root = document.documentElement
delete root.dataset.vt
delete root.dataset.vtDirection
done?.()
swapped = null
transition = null
}
return {
mode: 'out-in',
leave: (visit) => {
// Browsers without the API get a quick fade instead.
if (!('startViewTransition' in document)) return visit.current.animate({ opacity: [1, 0] }, { duration: 250, fill: 'forwards' })
before?.(visit)
document.documentElement.dataset.vt = name
document.documentElement.dataset.vtDirection = visit.direction
const ready = new Promise<void>((resolve) => (swapped = resolve))
transition = document.startViewTransition(() => ready)
transition.finished.catch(() => undefined).finally(reset)
// A visit replaced while it loads must not leave the page frozen, waiting for a swap.
visit.signal.addEventListener('abort', () => {
swapped?.()
transition?.skipTransition()
}, { once: true })
},
enter: (visit) => {
if (!('startViewTransition' in document)) return visit.next?.animate({ opacity: [0, 1] }, { duration: 250 })
if (!transition) return
after?.(visit)
swapped?.()
return transition.finished.catch(() => undefined)
},
}
} Reversing a transition when someone presses back, and following a finger with a gesture, work with Web Animations and GSAP. A promise or the View Transitions API finishes first instead.
Modes
A transition written as an object has a mode, which says in what order the two pages animate. A plain function is one animation that moves both pages together, so it runs sync.
sync
Both pages are on screen and animate together.
out-in
The old page leaves, then the new page enters.
in-out
The new page enters over the old one, then the old page leaves.
out-in is the default for an object, as in Barba and Swup. See each one running.
Gestures
Turn them on, then say where each one goes. A drag scrubs a sync transition.
createRouter({ gestures: { swipe: true, edgeBack: true, dismiss: true } }) <!-- Swipe left and right -->
<a href="/work/next" data-chasse-next>Next</a>
<a href="/work/previous" data-chasse-prev>Previous</a>
<!-- Drag down to close -->
<main data-chasse-container data-chasse-dismiss="/work"> Edge back needs nothing: it works whenever there is a page to go back to. Try them.
Webflow
Give every page's content the same wrapper class, then paste this into Site settings, Custom code, Footer code. The adapter restarts Webflow's interactions after each page and leaves its tabs and lightboxes alone.
<script src="https://cdn.jsdelivr.net/npm/@studio-lumio/chasse@0.6"></script>
<script>
Chasse.createRouter({
container: '.page-wrapper',
plugins: [Chasse.webflow()],
transition: () => 'fade',
transitions: {
fade: {
leave: ({ current }) =>
current.animate({ opacity: [1, 0] }, { duration: 400, fill: 'forwards' }),
enter: ({ next }) => next.animate({ opacity: [0, 1] }, { duration: 400 }),
},
},
})
</script> Webflow has no official API for this, and IX3 interactions are not covered. It has been tested against a stand-in for Webflow's runtime, so try it on your site. Test on the published site, not Designer preview.