Kinetic UI
Back to Introduction
Data Display

Magnetic Tooltip

A physics-based tooltip that magnetizes to your cursor and dynamically stretches based on velocity.

Quick Actions
CLI Installation
npx kinetic-ui-cli@latest add magnetic-tooltip
Magnetic Tooltip
Area

Installation

npx kinetic-ui-cli@latest add magnetic-tooltip

How It Works

The MagneticTooltip leverages framer-motion's useSpring and useMotionValue to track cursor position inside a bounding box. We then calculate the mathematical derivative (velocity) of the cursor's movement in real-time, and pass that value into a useTransform to dynamically scale, rotate, and squash the tooltip, giving it a true physical presence.

Usage Guide

1. Import the Component

Import the component into your React or Next.js page:

import { MagneticTooltip } from "@/components/creative/magnetic-tooltip";

2. Implementation Example

Render the component and customize its behavior by passing props:

import { MagneticTooltip } from "@/components/creative/magnetic-tooltip";

export default function Example() {
  return (
    <div className="w-full flex items-center justify-center p-8">
      <MagneticTooltip
        content="example"
        tooltipClassName="example"
      >
        <div>Content goes here</div>
      </MagneticTooltip>
    </div>
  );
}
Performance Notes
  • Uses CSS hardware acceleration via GPU transform-binds.
  • Damped interpolation minimizes paint-redraw flashes.
  • Tree-shakable import: only compiles elements requested.
Accessibility Notes
  • Full keyboard focus-ring navigation support (`Tab`/`Shift+Tab`).
  • ARIA roles mapped correctly for assistive screen readers.
  • Respects `prefers-reduced-motion` system toggles.