Lens

A interactive component that enables zooming into images, videos and other elements.

motion-sv
image_placeholder
Your next camp

See our latest and best camp destinations all across the five continents of the globe.

Installation

pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/lens.json

Usage

<script lang="ts">	import { Lens } from "#lib/components/magic/lens/index.js";</script>
<Lens>	<img src="https://images.unsplash.com/photo-1736606355698-5efdb410fe93" alt="Mountain lake" /></Lens>

Examples

Image Inspection

Inspect a high-resolution image with a larger lens and two-times zoom.

mountains reflected in a lake
move over the image to inspect the detail

Diagram Labels

Inspect compact request labels on hover without obscuring the diagram at rest.

browserroutercacheoriginrequesthitmiss
hover to inspect the request path

Props

Lens

A component for Lens.

NameTypeDefaultDescription
childrenSnippetContent wrapped by the lens (image, video, etc.).
zoomFactornumber1The zoom factor of the lens.
lensSizenumber100The size of the lens (diameter in pixels).
position{ x: number; y: number }{ x: 0, y: 0 }The position of the lens (x and y coordinates).
defaultPosition{ x: number; y: number }{ x: 0, y: 0 }The default position of the lens.
isStaticbooleanfalseWhether the lens is static (doesn't follow pointer).
durationnumber0.3The duration of the animation (seconds).
lensColorstring"rgba(255,255,255,0.5)"The color of the lens overlay.
ariaLabelstring"zoom lens"The aria label of the lens for accessibility.
classClassValue""Additional CSS classes to apply to lens container.