All components

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

Photo.jsx
<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-fit crop and corner radius.
  • zoomSrc fades 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

PropTypeDefaultDescription
srcstringThe image shown in place.
zoomSrcstringA larger image shown once it has loaded; keep the same aspect ratio.
marginnumber24Space kept around the zoomed image in pixels.
disabledbooleanfalseTurns zooming off.
onZoomChange(zoomed) => voidRuns with true when zoomed and false when closed.
backdropStyleCSSPropertiesInline style for the backdrop.
transitionTransitionspringA 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.

Used in these examples

Search

Type to search the documentation.