Skip to content
Back to the lab

Pointer follow · three strengths

Magnetic buttons

The button shifts toward the cursor and its label moves a little further than its plate; when the cursor leaves the range, both layers spring back. Three buttons show three strengths, and the dotted ring marks the range.

Source · GitHub

Based on GSAP's demo azmKBBJ: the box is measured once on pointerenter (once per hover, not per frame), pointermove multiplies the cursor's offset from the centre by a strength and writes it as x/y, and the inner layer moves 0.6x further; on leave both layers spring back on elastic.out. The first version attached the listeners to the layer that moves, which caused two problems. At ×0.75 the plate and the inner layer together moved 1.2x the cursor's offset, faster than the cursor, so the cursor was always over the button, pointerleave never fired, and a button could be dragged across half the screen. Near the boundary it also switched repeatedly between leave and enter, which showed as jitter. Now there are three layers: the outermost never moves and only listens and is measured, with a 20px hit area around it; the plate and the inner layer move separately. Whether the cursor is still in range is decided from the resting box plus the hit area, regardless of where the plate currently is. Mouse-type pointers only.

Source

Source files on GitHub:

Back to the lab