Field Notes
Landscape prints, small runs
Click a card → the thumbnail flies into the detail page.
Two documents, one animation
A same-document view transition wraps a DOM change in document.startViewTransition(). Across two separate HTML files there is no shared JavaScript moment to wrap, so the browser does the wrapping for you: both pages opt in with @view-transition { navigation: auto }, and the outgoing page is held on screen while the incoming one is prepared.
Naming the pair, not the page
The browser only animates elements it can match. Give the grid thumbnail and the detail hero the same view-transition-name and it treats them as one thing that moved — position, size and border radius are interpolated for free. Everything else falls back to the default root crossfade.
Why the name is set in JavaScript
A name has to be unique within a document. Six cards cannot all be shot. So the detail page — which has exactly one hero — claims the name in CSS, and the grid page claims it at the last possible moment, in the pageswap handler, for the single card being navigated to. On the way back, pagereveal does the same job before the first frame is painted, then releases the name once viewTransition.finished settles.
Tuning the motion
Every matched pair becomes a pseudo-element tree you can style like anything else. ::view-transition-group(*) sets one duration and easing for the whole navigation; targeting a single name lets the title crossfade quicker than the image travels, which is what stops the effect feeling syrupy.
Falling back
In a browser without cross-document transitions, every line above is inert and the navigation is an ordinary page load — nothing to polyfill, nothing to feature-detect. The reduced-motion block turns it off for anyone who has asked for less movement.
Description
A two-file Pen for the challenge: a grid of prints and a detail page, wired together with cross-document view transitions. The clicked thumbnail becomes the hero image on the next page, and comes home again on the back navigation. No framework, no router — one CSS at-rule and about thirty lines of JavaScript.
Tags
- 1,204
- 38.6k
- 0
Comments
More from this Challenge
- Shared-element list → detail
- Directional slide on back navigation
- Transition groups with view-transition-class