Skip to content
Pixelbits
Docs / Magnetic
Signature

Magnetic

Pulls its child toward the pointer when it comes close, and lets it spring back. Only on devices with a fine pointer and without reduced motion; the transform is set directly (no React render per frame).

Installation

npm: import
import { Magnetic } from "pixelbits/magnetic";
shadcn: copy the source
npx shadcn add https://pixelbits.ali-moradi-develop.com/r/magnetic.json

API

<Magnetic>

Pulls its child toward the pointer when it comes close, and lets it spring back. Only on devices with a fine pointer and without reduced motion; the transform is set directly (no React render per frame).

Example
<Magnetic><Button variant="primary">Start a project</Button></Magnetic>
PropTypeDefaultDescription
children*ReactElement—

The element to pull, usually a Button.

strengthnumber0.3

How strongly it follows: 0 none, 1 all the way to the pointer.

radiusnumber80

Distance in px around the element where the pull starts.

classNamestring—

Extra classes, merged into the child element.