StealThis .dev

Magnetic Cursor

A custom easing cursor (dot plus lagging ring) paired with magnetic buttons and links that pull toward the pointer inside a radius, snap back on leave, and grow their label on hover. Multiple targets, live tunable strength and radius, touch-hidden and reduced-motion aware.

Open in Lab
vanilla-js css
Targets: JS HTML

Code

Magnetic Cursor replaces the native pointer with a two-part cursor: a crisp dot that tracks the mouse exactly and a translucent ring that trails behind with spring-like easing. Around the page sit several magnetic targets — buttons, icon tiles, and links — that sense the pointer within a configurable radius and drift toward it, pulling their inner label along at a slightly stronger factor for a parallax feel. When the pointer leaves, every element eases back to rest, and hovered targets swell the ring so the cursor reads as “locked on.”

The interaction is driven by a single requestAnimationFrame loop that linearly interpolates the ring and each active target toward its goal, so motion stays smooth without piling up timers. Pointer offset is computed against each element’s center, clamped to the radius, and multiplied by a strength factor you can adjust live. Controls let you tune ring lag, magnet strength, and pull radius, and toggle the whole effect, while a readout reports the pointer coordinates and the currently captured target.

The component feature-detects coarse pointers and hides the custom cursor on touch devices, restoring the system pointer. It honors prefers-reduced-motion by disabling lag and magnetic drift while keeping focus outlines and hover states intact, and every target remains a real, keyboard-focusable element so the page works with or without the effect.