Move your cursor toward the button. Inside the attraction zone, the button follows a fraction of the pointer's offset, and its label follows half as far for a parallax feel. CSS handles the easing, so the script only sets transforms.
On touch screens there's no hover, so the button follows your finger while you press and drag it. touch-action: none stops that drag from scrolling the page.
With reduced motion on, the pull drops to about a third and the label parallax is skipped. It still responds, just calmly.
Tune it: pullStrength controls how far it travels, and attractionZone is the padding around the button that attracts.
Read the full walkthrough: A magnetic button in 30 lines of vanilla JS.