StealThis .dev

Lens Effect

Magnifying glass lens effect that follows the cursor, showing a zoomed circular area over content with smooth tracking and customizable zoom level.

Open in Lab
css javascript vue svelte
Targets: TS JS HTML React Vue Svelte

Code

Lens Effect

A magnifying glass effect that tracks the cursor and shows a zoomed circular view of the content underneath. The lens follows mouse movement smoothly with a subtle spring animation.

How it works

  1. A circular lens element is absolutely positioned and follows the mouse
  2. The lens contains a scaled clone of the background content via background-image + background-size
  3. Background position is offset based on cursor position to keep the zoom centered
  4. Smooth tracking uses lerp (linear interpolation) for a polished feel
  5. The lens hides when the cursor leaves the content area

Customization

  • ZOOM_LEVEL controls magnification (default 2x)
  • LENS_SIZE sets the diameter of the magnifying circle
  • Border, shadow, and chromatic aberration effects can be toggled
  • Works with images, text, or any HTML content

When to use it

  • Image galleries with detail zoom
  • Product image inspection
  • Map detail views
  • Interactive art / photography portfolios