Image Zoom

An image that zooms toward the pointer on hover.

image-zoom.tsx

Installation

1

Install the packages

npm install @prequelui/react motion

@prequelui/react reuses the primitive library your components already depend on.

2

Add the component

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/image-zoom.json

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/image-zoom.json

3

Turn on the motion

npx @prequelui/cli@latest animate image-zoom

The 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.

image-zoom.tsx
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.
spring 200 / 28pointer origintouch fallbackbounds clamped

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

PropTypeDefault
zoomScalenumber3
zoomOnHoverbooleantrue
zoomOnClickbooleantrue
disabledbooleanfalse
widthCSSProperties['width']"100%"
heightCSSProperties['height']"100%"
transitionTransitioncomponent spring or tween
classNamestring—

Built by Vidhal. The source is available on GitHub.

Last updated: 11/17/2026