The idea
A button sits inside a dashed circle labelled "attraction field". Move your cursor into the circle and the button leans toward it. Leave and it springs back. The circle lights up violet while you're inside it, so you can see the rule, not just the effect.
Why
Magnetic hover is one of those effects that's either delightful or deeply annoying, and the difference is all in the tuning. Too strong and the button runs away from you. Too weak and nobody notices. I wanted a demo that makes the hidden part of the interaction, the field, visible. Once you can see the field, you can talk about it.
It's also a useful argument about affordance. A button that moves toward you is quietly saying "yes, me, click me" before you've committed.
Approach
- Offset, not follow. The button moves 35% of the distance between its center and your cursor. It leans, it doesn't chase. That ratio is the whole personality of the effect.
- Springs smooth out the jitter. Raw pointer positions are noisy, so the x and y offsets each run through a spring (stiffness 200, damping 15). The button glides instead of twitching.
- Make the invisible visible. The dashed ring and the "attraction field" label change color while you're inside. In production I'd leave these out. In a lab they're the point.
Decisions & trade-offs
- Mouse only. The effect ignores touch and pen input. On a phone there's no hover. Your finger is the cursor, and a button that moves out from under your thumb is a bug.
- It still behaves like a button. It's a real
buttonwith a press-scale on tap, so keyboard and screen-reader users get a normal control. The magnetism is pure decoration on top. - Exaggerated on purpose. The demo is far stronger than I'd ever ship. Real magnetic buttons should move a few pixels at most.
What I'd try next
- A strength slider, so you can feel where "lean" becomes "flee".
- A version that respects the button's neighbours, so two magnetic buttons don't fight over your cursor.