Wrap a button and it leans toward a nearby pointer, then gives a soft press when clicked.
Move around the button · click to press
pnpm dlx shadcn@latest add @latheui/magneticPart of Lathe Pro. Set up your project once with your license key: npx latheui init --key <key>. See Lathe Pro.
Magnetic is part of Lathe Pro
The preview is live and free to try. The source, the install and every assembly come with Pro: $79 once, with lifetime updates.
Depends on
Also accepts native div attributes. It renders an inline-block wrapper.
| Prop | Type | Default | Description |
|---|---|---|---|
| strength | number | 0.22 | Share of the pointer's distance the content follows. 0 stays put, 1 sticks to the pointer. |
| range | number | 60 | How far past its edges the pull reaches, in pixels. |
<Magnetic strength={0.4} range={24}>
<Button size="icon" aria-label="Like"><HeartIcon /></Button>
</Magnetic>