Skip to content
Catalog
CONTENTS:Magnetic Button

Magnetic Button

A high-polish micro-interaction component engineered with Framer Motion springs. When the cursor nears the button, it smoothly attracts the element toward the cursor coordinates up to a configurable maximum distance threshold, dampening with natural Newtonian physics on exit.

Dependencies:
framer-motiontailwind-merge
Loading preview...

Examples

Select a preset to load into preview

Installation

pnpm add framer-motion tailwind-merge

Props

PropertyTypeDefaultDescription
maxDistancenumber30Maximum distance in pixels the button is allowed to pull toward the pointer.
stiffnessnumber150Spring stiffness coefficient. Higher values create a snappier attraction.
dampingnumber10Spring damping factor. Controls oscillation deceleration.
massnumber0.1Simulated physical mass of the button. Lower mass feels lighter and faster.
classNamestringundefinedTailwind CSS classes for styling the inner interactive button element.
bgClassNamestringundefinedTailwind CSS classes for the magnetic backdrop or container element.