asafefe.dev

Magnetic

A wrapper that pulls its child toward the cursor with spring physics.

motion

Installation

$ pnpm dlx shadcn@latest add @soultel/magnetic

No namespace set up? npx shadcn@latest add https://asafefe.dev/r/magnetic.json works too.

Manual installation
  1. 1. Install the dependencies.
    terminal1 lines
    npm install motion
  2. 2. Copy the source from the Code tab into components/magnetic.tsx.

Usage

example.tsx9 lines
import { Magnetic } from "@/components/magnetic"

export function Example() {
  return (
    <Magnetic strength={0.5}>
      <button>Hover me</button>
    </Magnetic>
  )
}

Props

PropTypeDefaultDescription
strengthnumber0.4Share of the cursor offset to follow.