An image that zooms toward the pointer on hover.
Installation
Install the packages
npm install @prequelui/react motion@prequelui/react reuses the primitive library your components already depend on.
Add the component
npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/image-zoom.jsonnpx shadcn@latest add https://animate.prequelui.terravidhal.me/r/image-zoom.json
Turn on the motion
npx @prequelui/cli@latest animate image-zoomThe CLI finds the component through components.json, swaps the import and removes the CSS animation classes that Motion replaces.
Usage
Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.
import { ImageZoom } from "@/components/prequelui/effects/image-zoom";
export default function Demo() {
return (
<ImageZoom zoomScale={2.4} width={300} height={176} className="rounded-xl border">
<img src="/cover.jpg" alt="" className="h-full w-full object-cover" />
</ImageZoom>
);
}import { ImageZoom } from "@/components/prequelui/image-zoom";
export function Variant() {
return (
<ImageZoom tempo={1.2}>
…
</ImageZoom>
);
}Animation
The image is scaled inside a clipping container and its transform origin follows the pointer. Hovering magnifies, leaving returns to scale 1, and a click toggles the zoom for touch devices. The origin is capped to the container bounds so an edge never shows empty space.
- Default spring: stiffness 200, damping 28.
- Pointer position is converted to percentages, so the origin survives a resize.
- Coarse pointers use touch events and click-to-toggle instead of hover.
- Reduced motion keeps the pointer origin but removes the scale.
API Reference
Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.
ImageZoom
| Prop | Type | Default |
|---|---|---|
| zoomScale | number | 3 |
| zoomOnHover | boolean | true |
| zoomOnClick | boolean | true |
| disabled | boolean | false |
| width | CSSProperties['width'] | "100%" |
| height | CSSProperties['height'] | "100%" |
| transition | Transition | component spring or tween |
| className | string | — |