Menu

How to animate a lightbox out of a cropped thumbnail
📰

How to animate a lightbox out of a cropped thumbnail

DEV Community: react·Esdras Santos·12 days ago
#VOxJetpC
#devtoreact#devto#dev#thumbnail#scale
Reading 0:00
15s threshold

Click a photo in a grid and a good lightbox doesn't just fade in. The photo grows out of the thumbnail you clicked, and when you close it, it shrinks back into the same spot. Your eye never loses track of it.

Most implementations get close and then break on one detail: the thumbnail is usually cropped. Grids use object-fit: cover so every cell has the same shape, which means the thumbnail shows only the middle of the photo. Grow the full image from that box and you see a jump in the first frame, because the edges the thumbnail was hiding suddenly appear.

This is how liftbox handles it. The whole thing is about thirty lines.

Step 1: lay the image out where it will end up

Render the lightbox with the image at its final size and position, then measure both boxes:

const to = image . getBoundingClientRect (); // where the image rests const from = thumbnail .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.