Magnetic Hover
atlas-ui/magnetic-hoverFreeComponent
A smooth magnetic hover interaction that subtly pulls elements toward the with using spring based motion animations.
Live preview
live · rendered by the registry
Rendered by atlas-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://atlasui.dev/r/magnetic-hover.jsonSource
1"use client";23import { useRef, useState } from "react";45import { motion } from "motion/react";67interface MagneticHoverProps {8 children: React.ReactNode;9 strength?: number;10}1112export const MagneticHover = ({13 children,14 strength = 1,15}: MagneticHoverProps) => {16 const ref = useRef<HTMLDivElement>(null);1718 const [position, setPosition] = useState({ x: 0, y: 0 });1920 const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {21 if (!ref.current) return;2223 const { left, top, width, height } = ref.current.getBoundingClientRect();24 const x = (e.clientX - (left + width / 2)) * strength;25 const y = (e.clientY - (top + height / 2)) * strength;26 setPosition({ x, y });27 };2829 const handleMouseLeave = (e: React.MouseEvent<HTMLDivElement>) => {30 setPosition({ x: 0, y: 0 });31 };3233 const { x, y } = position;3435 return (36 <motion.div37 ref={ref}38 onMouseMove={handleMouseMove}39 onMouseLeave={handleMouseLeave}40 animate={{ x, y }}41 transition={{ type: "spring", stiffness: 150, damping: 15, mass: 0.2 }}42 >43 {children}44 </motion.div>45 );46};
What it pulls in
npm packages
Files it writes
More from atlas-ui
All 99 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Mobile Navbaranimated-mobile-navbar | atlas-ui | Components | Free | 2 deps | |
| Blend Mouse Trailerblend-mouse-trailer | atlas-ui | Components | Free | 1 dep | |
| Blob Mouse Trailerblob-mouse-trailer | atlas-ui | Components | Free | 1 dep | |
| Box Revealbox-reveal | atlas-ui | Components | Free | 1 dep | |
| Cascade Textcascade-text | atlas-ui | Components | Free | 1 dep | |
| Dot And Circle Mouse Trailerdot-and-circle-mouse-trailer | atlas-ui | Components | Free | 1 dep | |
| Fancy Theme Togglefancy-theme-toggle | atlas-ui | Components | Free | 1 dep | |
| Hacker Texthacker-text | atlas-ui | Components | Free | no deps |
