Micro-interactions

Crossing

A gallery-to-detail crossing on the View Transitions API, where one element is the same object in both views.

Install

bun add clsx tailwind-merge

Then copy 2 files into your project:

  • components/registry/crossing/crossing.tsx
  • lib/utils.ts

Props

PropTypeDefaultDescription
durationnumber380Length of the crossing. Applied to the shared elements and the view together through pseudo-element rules the component scopes to itself, so it never retimes a transition something else on the page is running.
easing"expressive" | "standard" | "linear""expressive"Curve on the travel. Expressive arrives fast and settles; standard is the material curve; linear is there to show what the easing is worth, which on a morph is most of it.
shareTitlebooleantrueCarry the title across as a second shared element. Off, only the tile travels and the title cross-fades with the rest — the clearest way to see what a shared element buys over a crossfade.
exit"hold" | "fade" | "slide""hold"What the outgoing copy of the tile does while the incoming one arrives. Hold keeps it opaque underneath and is the default: it is the only one with no instant where two gradients are both half there. Fade is the browser's own behaviour, kept so the difference is visible; slide sends the old one off as the new lands.
radiusnumber12Corner radius of the frame and, three px in, the tiles.
viewTransitionbooleantrueRun the API at all. Off takes exactly the path an unsupported browser takes — the state update, bare — which is the only honest way to see the fallback. A view transition cannot be shortened, only skipped.
announcebooleantrueAnnounce the destination in a live region. A view transition is invisible to assistive tech, so a crossing that says nothing is a dead end for anyone not watching the pixels.
accentColorstring (hex)"#a855f7"Focus ring, and the mark on the card you came back from — drawn only once the crossing has finished. Anything painted on the shared element while it is in flight is captured into the snapshot and travels across the frame with it.

What It Demonstrates

View transition
The browser morphs between two states or pages, connecting shared elements.
Page transition
An animation that plays when navigating from one page or route to another.
Shared element transition
An element travels and transforms from one position into another, like a thumbnail expanding into a card.
Crossfade
One element fades out as another fades in, in the same spot.
Morph
One shape smoothly turns into another shape, e.g. Dynamic Island.

Related Components

Appears In