Patterns Medium
Magnetic Cursor
Custom cursor with spring-based following and magnetic attraction to interactive elements.
vanilla-jsspring-physics
Targets: JS HTML
Code
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root {
--bg: #070a12;
--panel: #121a2b;
--border: #263249;
--text: #f0f4fb;
--muted: #8a95a8;
--accent: #86e8ff;
--neon-purple: #ae52ff;
--neon-pink: #ff40d6;
}
body {
background: var(--bg);
color: var(--text);
font-family: 'Inter', 'SF Pro Display', system-ui, sans-serif;
min-height: 100vh;
cursor: none;
overflow-x: hidden;
}
/* Restore cursor for touch devices */
@media (hover: none) {
body { cursor: auto; }
.cursor-ring, .cursor-dot { display: none; }
}
/* ── Custom cursor ── */
.cursor-ring {
position: fixed;
top: 0;
left: 0;
width: 40px;
height: 40px;
border: 2px solid rgba(134, 232, 255, 0.5);
border-radius: 50%;
pointer-events: none;
z-index: 99999;
transform: translate(-50%, -50%);
transition: width 0.25s ease, height 0.25s ease, border-color 0.25s ease, background 0.25s ease;
will-change: transform;
}
.cursor-ring.hovering {
width: 60px;
height: 60px;
border-color: var(--accent);
background: rgba(134, 232, 255, 0.06);
}
.cursor-ring.clicking {
width: 30px;
height: 30px;
border-color: var(--neon-pink);
}
.cursor-dot {
position: fixed;
top: 0;
left: 0;
width: 6px;
height: 6px;
background: var(--accent);
border-radius: 50%;
pointer-events: none;
z-index: 99999;
transform: translate(-50%, -50%);
will-change: transform;
}
/* ── Page layout ── */
.page {
max-width: 1000px;
margin: 0 auto;
padding: 5rem 2rem 4rem;
}
.header {
text-align: center;
margin-bottom: 4rem;
}
.eyebrow {
display: inline-block;
font-size: 0.7rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.18em;
color: var(--accent);
margin-bottom: 1rem;
}
h1 {
font-size: clamp(2.2rem, 6vw, 4rem);
font-weight: 700;
letter-spacing: -0.03em;
}
.subtitle {
font-size: clamp(0.9rem, 2vw, 1.05rem);
color: var(--muted);
max-width: 500px;
margin: 0.75rem auto 0;
line-height: 1.6;
}
/* ── Button grid ── */
.button-grid {
display: flex;
gap: 1rem;
justify-content: center;
flex-wrap: wrap;
margin-bottom: 3rem;
}
.mag-btn {
position: relative;
padding: 0.85rem 2.2rem;
border-radius: 999px;
background: linear-gradient(135deg, rgba(134, 232, 255, 0.12), rgba(174, 82, 255, 0.08));
border: 1px solid rgba(134, 232, 255, 0.2);
color: var(--accent);
font: 600 0.9rem/1 'Inter', system-ui, sans-serif;
cursor: none;
transition: border-color 0.3s, box-shadow 0.3s;
will-change: transform;
}
.mag-btn span { pointer-events: none; }
.mag-btn:hover {
border-color: var(--accent);
box-shadow: 0 0 20px rgba(134, 232, 255, 0.15);
}
.mag-btn.accent {
background: linear-gradient(135deg, var(--accent), #6ec1ff);
color: var(--bg);
border-color: transparent;
}
.mag-btn.accent:hover {
box-shadow: 0 0 30px rgba(134, 232, 255, 0.3);
}
.mag-btn.outline {
background: transparent;
border-color: var(--border);
color: var(--muted);
}
.mag-btn.outline:hover {
border-color: var(--neon-purple);
color: var(--neon-purple);
}
/* ── Cards ── */
.card-row {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.25rem;
margin-bottom: 3rem;
}
.mag-card {
background: var(--panel);
border: 1px solid var(--border);
border-radius: 14px;
padding: 1.5rem;
cursor: none;
transition: border-color 0.3s, box-shadow 0.3s;
will-change: transform;
}
.mag-card:hover {
border-color: rgba(134, 232, 255, 0.3);
box-shadow: 0 4px 24px rgba(134, 232, 255, 0.06);
}
.card-icon {
font-size: 1.5rem;
font-weight: 700;
color: var(--accent);
margin-bottom: 0.75rem;
opacity: 0.6;
}
.mag-card h3 {
font-size: 1rem;
font-weight: 600;
margin-bottom: 0.5rem;
}
.mag-card p {
font-size: 0.85rem;
color: var(--muted);
line-height: 1.5;
}
/* ── Links ── */
.link-row {
display: flex;
gap: 2rem;
justify-content: center;
flex-wrap: wrap;
}
.mag-link {
color: var(--accent);
text-decoration: none;
font-size: 0.9rem;
font-weight: 500;
padding: 0.4rem 0;
border-bottom: 1px solid rgba(134, 232, 255, 0.2);
cursor: none;
transition: border-color 0.3s;
will-change: transform;
}
.mag-link:hover {
border-bottom-color: var(--accent);
}
/* ── Reduced motion ── */
.reduced-motion .cursor-ring,
.reduced-motion .cursor-dot { display: none; }
.reduced-motion body { cursor: auto; }
.reduced-motion [data-magnetic] { cursor: pointer; }
@media (max-width: 640px) {
.page { padding: 3rem 1rem 3rem; }
.card-row { grid-template-columns: 1fr; }
}Magnetic Cursor
Custom cursor with spring-based following and magnetic attraction to interactive elements.
Source
- Repository:
libs-genclaude - Original demo id:
16-magnetic-cursor
Notes
Custom cursor with spring-based following and magnetic attraction to interactive elements.