An image that zooms in where the pointer is, on hover or on click.
Installation
Usage
import { Image, ImageZoom } from '@animate-ui/react/primitives/effects/image-zoom';
export function ProductPhoto() {
return (
<ImageZoom width={320} height={320} aria-label="Product photo, zoomable">
<Image src="/product.webp" alt="The product" />
</ImageZoom>
);
}Image renders an img by default; pass as to use your framework's image component (as={NextImage}).
Animation
- Hovering zooms in to
zoomScaleon a spring, from the point under the pointer; moving the pointer pans the zoom. - Clicking (or tapping on touch screens) toggles the zoom. The cursor shows whether a click zooms in or out.
- Under reduced motion, the zoom jumps instead of scaling.
API Reference
ImageZoom
| Prop | Type | Default |
|---|---|---|
zoomScale? | number | 3 |
transition? | Transition | { type: 'spring', stiffness: 200, damping: 28 } |
zoomOnHover? | boolean | true |
zoomOnClick? | boolean | true |
disabled? | boolean | false |
width? | React.CSSProperties['width'] | '100%' |
height? | React.CSSProperties['height'] | '100%' |
children | React.ReactElement | - |
...props? | React.ComponentProps<'div'> | - |
Image
| Prop | Type | Default |
|---|---|---|
objectFit? | React.CSSProperties['objectFit'] | 'cover' |
as? | React.ElementType | 'img' |
...props? | React.ComponentProps<T> | - |
Credits
- Inspired by Jurre's Hover Zoom Framer component.
