Loading effect…
Loading preview…
buttons · react · free
A button that gently follows the pointer for a magnetic feel.
import { MagneticButton } from "@/components/znverse/magnetic-button/MagneticButton";
<MagneticButton strength={0.35}>
Hover me
</MagneticButton>npx znverse add magnetic-button"use client";
import {
useCallback,
useEffect,
useRef,
useState,
type CSSProperties,
type PointerEvent,
type ReactNode,
} from "react";
type MagneticButtonProps = {
children?: ReactNode;
className?: string;
strength?: number;
};
export function MagneticButton({
children = "Magnetic Button",A button that gently follows the pointer for a magnetic feel.
Copy src/MagneticButton.tsx into your React project. No extra dependencies.
import { MagneticButton } from "./MagneticButton";
export function Example() {
return <MagneticButton>Get started</MagneticButton>;
}| Prop | Type | Default | What it does |
|---|---|---|---|
strength | number | 0.35 | How far the button follows the pointer, from 0 (still) to 1 |
className | string | Extra class on the button |
"use client")prefers-reduced-motion