terra vidhal

Image Zoom

Component

About

An image that zooms toward the pointer on hover or tap, with a controllable zoom origin.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Image Zoom to your project and fits it to your theme.

Code

How Image Zoom is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

/**
 * PrequelUI Animate — MIT — https://prequeluianimate.terravidhal.me
 */

import * as React from "react";
import { Maximize2 } from "lucide-react";
import { Image, ImageZoom } from "@/components/ui/image-zoom";

const ART =
  "data:image/svg+xml;charset=utf-8," +
  encodeURIComponent(
    `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 600">
      <defs>
        <linearGradient id="bg" x1="0" y1="0" x2="1" y2="1">
          <stop offset="0%" stop-color="#0f172a"/>
          <stop offset="55%" stop-color="#1d4ed8"/>
          <stop offset="100%" stop-color="#22d3ee"/>
        </linearGradient>
        <radialGradient id="glow" cx="30%" cy="28%" r="68%">
          <stop offset="0%" stop-color="#f0abfc" stop-opacity="0.95"/>
          <stop offset="100%" stop-color="#f0abfc" stop-opacity="0"/>
        </radialGradient>
      </defs>
      <rect width="800" height="600" fill="url(#bg)"/>
      <circle cx="235" cy="195" r="225" fill="url(#glow)"/>
      <g fill="none" stroke="#ffffff" stroke-opacity="0.28" stroke-width="2">
        <circle cx="565" cy="385" r="185"/>
        <circle cx="565" cy="385" r="122"/>
        <circle cx="565" cy="385" r="60"/>
      </g>
      <g fill="#ffffff" fill-opacity="0.85">
        <circle cx="565" cy="385" r="5"/>
        <circle cx="690" cy="120" r="3"/>
        <circle cx="120" cy="470" r="4"/>
      </g>
      <text x="56" y="540" fill="#ffffff" font-family="ui-sans-serif, system-ui, sans-serif" font-size="46" font-weight="700">Zoom in</text>
    </svg>`,
  );

export default function ImageZoomDemo() {
  return (
    <div className="flex min-h-screen items-center justify-center bg-gradient-to-br from-slate-100 via-white to-slate-200 p-6 dark:from-black dark:via-slate-950 dark:to-slate-900">
      <div className="w-full max-w-3xl rounded-[2rem] border border-border bg-background/90 p-5 shadow-2xl shadow-slate-900/10 backdrop-blur dark:shadow-black/40">
        <div className="mb-4 flex items-end justify-between gap-4 px-2">
          <div className="flex flex-col gap-1">
            <p className="text-[11px] font-medium uppercase tracking-[0.35em] text-muted-foreground">
              PrequelUI Animate
            </p>
            <h1 className="text-2xl font-semibold tracking-tight text-foreground">
              Image Zoom
            </h1>
          </div>
          <span className="hidden items-center gap-1.5 rounded-full border border-border bg-muted/40 px-3 py-1.5 text-xs font-medium text-muted-foreground sm:inline-flex">
            <Maximize2 className="size-3.5" />
            Move cursor · click to toggle
          </span>
        </div>

        <ImageZoom
          className="h-[420px] w-full rounded-[1.5rem] border border-black/10 shadow-inner dark:border-white/10"
          zoomScale={2.6}
        >
          <Image src={ART} alt="Abstract gradient artwork with glowing rings" />
        </ImageZoom>

        <p className="mt-4 px-2 text-center text-sm text-muted-foreground">
          Hover to zoom toward the pointer; tap or click to toggle the zoom.
        </p>
      </div>
    </div>
  );
}

Dependencies

More by terra vidhal

View all
  • Morphing Text

    Morphing Text

  • File Drop

    File Drop

  • Sliding Number

    Sliding Number

  • Liquid Button

    Liquid Button

  • Gravity Stars Background

    Gravity Stars Background

Explore more

Part of PrequelUI Animate — browse the full library on 21st.dev.