Ultra-lightweight, high-60FPS magnetic cursor attraction physics engine for Web UI buttons, icons, avatars, and cards. Multi-layered 3D depth, zero layout shift, and 0 idle CPU overhead.
import { magnetic } from 'magneticui';
magnetic.attach(document.querySelector('#my-btn'), {
radius: 90,
strength: 0.4,
stiffness: 160,
damping: 15,
childSelector: '.inner-icon',
childStrength: 0.6
});
import { magnetic } from 'magneticui';
// Attach magnetic presets to elements
const btn = document.querySelector('#btn');
magnetic.button(btn);
// Or custom magnetic parameters with 3D depth
magnetic.attach(btn, {
radius: 90,
strength: 0.4,
childSelector: '.btn-icon',
childStrength: 1.2
});
'use client';
import { Magnetic } from 'magneticui/react';
export function ActionButton() {
return (
<Magnetic radius={90} strength={0.4}>
<button>Magnetic Action</button>
</Magnetic>
);
}