Magnetic
strength 0.35Pulls its content toward the cursor inside the field, then springs back when the pointer leaves.
Hover is on or off. near-field hands your CSS the distance in between, as three custom properties.
npm i near-fieldEvery subscribed element carries them. Your CSS decides what proximity means.
--nf--nf-x--nf-yPick a preset, gentle, snappy, or instant, instead of turning physics knobs.
Pulls its content toward the cursor inside the field, then springs back when the pointer leaves.
Leans toward the cursor, easing in before the pointer arrives.
A soft light that tracks the cursor and brightens with proximity.
React components, a callback for canvas work, or plain JavaScript with no framework.
import { useNearField } from "near-field";
function Card() {
const ref = useNearField({ radius: 140 });
return <div ref={ref} className="card" />;
}
/* --nf eased 0..1, --nf-x / --nf-y unit vector */
.card {
transform: translate(
calc(var(--nf-x) * var(--nf) * 8px),
calc(var(--nf-y) * var(--nf) * 8px)
);
}