Components
Magnetic Button
A button that leans toward the cursor.
<MagneticButton>
<button>Get started</button>
</MagneticButton>Installation
npx shadcn@latest add https://ui.zjkm.tech/r/magnetic-button.jsonimport { MagneticButton } from "@/components/magnetic-button"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
Wrap a button or link. When a mouse comes near, it leans toward the cursor, and it springs back when the cursor leaves. Touch and keyboard use are unchanged, and the button keeps its own semantics.
import { MagneticButton } from "@/components/magnetic-button";
export function Cta() {
return (
<MagneticButton>
<button>Get started</button>
</MagneticButton>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | Your button or link. | |
strength | number | 0.35 | Share of the cursor's offset the button follows, from 0 to 1. |
radius | number | 80 | Pixels around the button where the pull starts. |
className | string | Classes for the wrapper. |
With reduced motion, the button stays put.