StealThis .dev

Interactive Grid Pattern

A canvas-based grid pattern that reacts to mouse movement, illuminating cells near the cursor with distance-based brightness falloff.

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

Code

Interactive Grid Pattern

A canvas-based grid that responds to mouse movement in real time. Cells near the cursor illuminate with a smooth distance-based brightness falloff, creating a spotlight-like reveal effect.

How it works

  1. A full-screen HTML Canvas draws a grid of rounded rectangles
  2. On every mousemove event, the cursor position is tracked
  3. Each cell’s brightness is calculated based on its Euclidean distance from the cursor
  4. requestAnimationFrame ensures smooth 60fps rendering with lerped transitions

Customization

  • CELL_SIZE and GAP control grid density
  • RADIUS sets the illumination falloff range
  • BASE_COLOR and GLOW_COLOR define the dim and lit cell colors
  • The brightness curve uses an inverse-square falloff for natural feel

When to use it

  • Interactive hero backgrounds
  • Mouse-reactive ambient effects
  • Dashboard backgrounds with depth
  • Portfolio sites and creative showcases