Presence

Motion · Next.js

A photo gallery that slides the way you go

Swipe or step through the collection's photos: each comes in from the side you're heading to, and the last one leaves by the other.

With Wardic: Solid 1 · Solid 2

Live demo

Reduced motion: The photos cross-fade in place. The demo gives the slide no distance under reduced motion (the system's setting through createReducedMotion, or the header's switch): left to Wardic's rule, which snaps a positional value to its target, a leaving photo would jump aside at once and fade there.

Beside Wardic

Motion changes the photo by giving it a new key: React unmounts the old element, which AnimatePresence keeps for its exit, and mounts a new one. Solid has no keys on elements: <Show when={…} keyed> makes a new photo each time the piece shown changes, and the presence takes the old one out the same way. The swipe is the same test on the drag's release, from the photo's onDragEnd (Solid 1's too); Solid 2 gives each photo in turn one ward that holds the drag, and hears its releases through when("dragEnd").

The code

Highlighting…