Magnetic Button

A button pulled toward the cursor that springs back elastically.

gsapMIT · free

Installation

npx shadcn@latest add https://ombakui.com/r/magnetic-button.json

Usage

import { MagneticButton } from "@/components/magnetic-button";

<MagneticButton>Start a project</MagneticButton>

<MagneticButton as="a" href="/work" className="border bg-transparent text-foreground">
  See the work
</MagneticButton>

Props

PropTypeDefaultDescription
asT"button"Render as another element, e.g. "a". From a Server Component, pass a tag name (not a component like Link).
children*ReactNode–
strengthnumber0.35How far the button follows the cursor, 0–1.
innerStrengthnumber0.2Extra pull on the inner label for a layered feel, 0–1.
radiusnumber30Extra space in px around the button where the pull starts.
classNamestring–