Skip to content
Apex Motion — copy-paste animated components✓ Free tier — copy and ship✓ Live previews✓ Performance-first, no bloat✓ You own the code✓ Stripe-secured checkout
——Button · Free

Magnetic Button

A button that leans toward the cursor and springs back. The detail that makes a site feel premium.

import { motion, useMotionTemplate, useMotionValue } from "framer-motion";
import { useRef } from "react";

export function MagneticButton({ label = "Hover me" }) {
  const ref = useRef(null);
  const x = useMotionValue(0);
  const y = useMotionValue(0);
  const transform = useMotionTemplate`translate(${x}px, ${y}px)`;

  const onMove = (e) => {
    const r = ref.current.getBoundingClientRect();
    x.set((e.clientX - (r.left + r.width / 2)) * 0.4);
    y.set((e.clientY - (r.top + r.height / 2)) * 0.4);
  };
  const reset = () => { x.set(0); y.set(0); };

  return (
    <motion.button
      ref={ref}
      onMouseMove={onMove}
      onMouseLeave={reset}
      style={{ transform }}
      transition={{ type: "spring", stiffness: 200, damping: 12 }}
      className="rounded-full bg-accent px-7 py-3 font-medium text-black"
    >
      {label}
    </motion.button>
  );
}

How it works

Magnetic Button is a hand-built button component for React, styled with Tailwind and animated with Framer Motion — no heavy dependency tree, no 60-package install. Drop it in, keep your bundle lean, and it stays performant on real devices. It's free — copy the code above and ship it.

← Browse all components
Reviews

We’re early. Real reviews only.

Apex Digital launched recently. Every purchase comes with a request for honest feedback through our help center. When real buyers write real reviews, they go here — with their permission, by name. Until then, this section stays empty. No fakes. No stock photos. No bullshit.

Used something from the catalog? Leave honest feedback →

While you’re here…