Kinetic UI
Back to Introduction
Media Components

Magnetic Depth Gallery

An interactive grid that mimics physical depth-of-field by dynamically blurring and scaling images based on their distance from your cursor.

Quick Actions
CLI Installation
npx kinetic-ui-cli@latest add magnetic-depth-gallery
Magnetic Depth Gallery

Depth of Field Gallery

Move your cursor over the grid.

Abstract 1
Abstract 2
Abstract 3
Abstract 4
Abstract 5
Abstract 6

Installation

npx kinetic-ui-cli@latest add magnetic-depth-gallery

Architecture

This component calculates Euclidean distance directly in a 60fps useAnimationFrame loop to achieve its effect:

  1. A single onMouseMove event listener is attached to the parent container. This writes the cursor's X and Y coordinates into highly-performant Framer Motion useMotionValues.
  2. Every image in the gallery subscribes to these motion values.
  3. On every frame, each image calculates its exact center point on the screen and measures its distance to the cursor.
  4. Using linear interpolation, the component dynamically scales and sharpens items that are near the cursor, while fading and applying CSS blur() to items that are far away.

The result is a stunning "macro lens" depth-of-field effect that reacts instantly to user input.

Usage Guide

1. Import the Component

Import the component into your React or Next.js page:

import { MagneticDepthGallery } from "@/components/creative/magnetic-depth-gallery";

2. Implementation Example

Render the component and customize its behavior by passing props:

import { MagneticDepthGallery } from "@/components/creative/magnetic-depth-gallery";

export default function Example() {
  return (
    <div className="w-full flex items-center justify-center p-8">
      <MagneticDepthGallery
        images{/* value */}
        itemClassName="example"
      />
    </div>
  );
}
Performance Notes
  • Uses CSS hardware acceleration via GPU transform-binds.
  • Damped interpolation minimizes paint-redraw flashes.
  • Tree-shakable import: only compiles elements requested.
Accessibility Notes
  • Full keyboard focus-ring navigation support (`Tab`/`Shift+Tab`).
  • ARIA roles mapped correctly for assistive screen readers.
  • Respects `prefers-reduced-motion` system toggles.