Specimen 1: The Magnet Copier
Magnetica copians
Reviewed ✓Copies its own implementation snippet to your clipboard. Within its enclosure it drifts up to 6px toward a mouse pointer.
Keyboard: Fully operable; magnetism never applies to keyboard focus, so focus rings stay put.
Implementation snippet
const btn = document.querySelector('.magnet');
const zone = btn.parentElement;
zone.addEventListener('pointermove', (e) => {
if (e.pointerType !== 'mouse' || matchMedia('(prefers-reduced-motion: reduce)').matches) return;
const r = btn.getBoundingClientRect();
const dx = (e.clientX - (r.left + r.width / 2)) * 0.12;
const dy = (e.clientY - (r.top + r.height / 2)) * 0.12;
const clamp = (v) => Math.max(-6, Math.min(6, v));
btn.style.translate = clamp(dx) + 'px ' + clamp(dy) + 'px';
});
zone.addEventListener('pointerleave', () => (btn.style.translate = '0 0'));
btn.addEventListener('click', () => navigator.clipboard.writeText(SNIPPET));