MotionZoom
An image that zooms from its place to full screen; drag it away to close.
WebReact NativeOverlays
Try it
Preparing the example…
Shortest usage
<MotionZoom
src={photo.thumb}
zoomSrc={photo.full}
width={240}
height={160}
style={{ objectFit: 'cover', borderRadius: 12 }}
/>;What it handles for you
- A click, Enter or Space zooms the image from where it is to fill the screen inside
margin. - The zoomed copy starts exactly as the thumbnail looks, with its
object-fitcrop and corner radius. zoomSrcfades in once it has loaded.- A click, Escape or dragging away closes it; a quick throw closes too, and a short drag springs back.
Use it for
- A photo grid.
- A product gallery.
- Images inside a blog post.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
src | string | The image shown in place. | |
zoomSrc | string | A larger image shown once it has loaded; keep the same aspect ratio. | |
margin | number | 24 | Space kept around the zoomed image in pixels. |
disabled | boolean | false | Turns zooming off. |
onZoomChange | (zoomed) => void | Runs with true when zoomed and false when closed. | |
backdropStyle | CSSProperties | Inline style for the backdrop. | |
transition | Transition | spring | A timing curve { duration, easing } or a spring { tempo: 'spring', spring }. Springs keep their momentum when interrupted. |
Other props go to the rendered element, so className, style and event handlers work as usual.
Web and React Native
The overlay exists only while zoomed (a top-layer dialog on the web), so the image can sit anywhere, even inside a paragraph. Other props go to the img.
On React Native pass source and zoomSource; the overlay is a transparent Modal.