Magnet
Web (React)
A micro-interaction component that pulls an element towards the mouse cursor.
A simple but highly effective physics micro-interaction. It wraps any element and pulls it towards the mouse cursor as it approaches, creating a magnetic gravity effect.
Installation
CLI
npx @modus-ui/cli add magnetManual
- Copy the code from the component tab.
- Create a file at
components/ui/magnet.tsx. - Paste the code.
Usage
tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
padding | number | 100 | Distance in pixels around the element within which the pull starts. |
disabled | boolean | false | Turns the magnetic effect off. |
magnetStrength | number | 2 | Divisor for the pull; higher values move the element less. |
activeTransition | string | "transform 0.3s ease-out" | CSS transition used while the cursor is in range. |
inactiveTransition | string | "transform 0.5s ease-in-out" | CSS transition used when the element springs back. |
wrapperClassName | string | "" | Classes for the outer wrapper. |
innerClassName | string | "" | Classes for the moving inner element. |
Comments