Rolling ball
Cursor, pointer feedback. Rolls by the distance it travels.
You are using it. Move your mouse.
- Sport
- Football
- Move
- Rolls by the distance it travels.
- For
- Cursor, pointer feedback
spring 900 / 52 · rolls by distance · reduced: no roll
01 Install
npx shadcn@latest add https://moveui-red.vercel.app/r/rolling-ball.jsonIt brings the tokens with it. The first time, import the tokens once in your root layout:
import "@/components/moveui/tokens.css";Not using shadcn? Copy the files below into components/moveui/, and tokens.css next to them.
02 Use it
import { RollingBall } from "@/components/moveui/rolling-ball/rolling-ball";
// Mount once, in your root layout. It does nothing on touch screens.
<body>
{children}
<RollingBall />
</body>03 Or ask your agent
Paste this into Claude Code, Cursor or any coding agent. It installs the piece and wires it in.
Add the Move UI "Rolling ball" piece to this project. It's for: Cursor, pointer feedback.
1. Install it: npx shadcn@latest add https://moveui-red.vercel.app/r/rolling-ball.json
2. If the project doesn't import the Move UI tokens yet, add this once to the root layout: import "@/components/moveui/tokens.css";
3. Use it like this, adapted to where it belongs in my code:
import { RollingBall } from "@/components/moveui/rolling-ball/rolling-ball";
// Mount once, in your root layout. It does nothing on touch screens.
<body>
{children}
<RollingBall />
</body>
Keep its reduced-motion behaviour and keyboard support. Don't hardcode durations, easing or colours: they come from the --ml-* tokens.
Docs: https://moveui-red.vercel.app/pieces/rolling-ballWant your agent to know the whole library and its motion rules? Add the Move UI skill to your project:
npx shadcn@latest add https://moveui-red.vercel.app/r/skill.json04 Code
"use client";
import { useEffect, useRef } from "react";
import "./rolling-ball.css";
const HOT = 'a, button, [role="button"], [role="tab"], summary, label, input, select, textarea';
const num = (name: string, fallback: number) => {
const v = parseFloat(getComputedStyle(document.documentElement).getPropertyValue(name));
return Number.isFinite(v) ? v : fallback;
};
/**
* Rolling ball: a chrome football pointer. It follows on a stiff spring, rolls by the distance it
* travels (like a real ball on the floor) and grows a little over anything clickable.
* Mount once, anywhere. Does nothing on touch screens. Spring values come from --ml-ball-* tokens.
*/
export function RollingBall({ hot = HOT }: { hot?: string }) {
const ballRef = useRef<HTMLDivElement>(null);
const skinRef = useRef<HTMLSpanElement>(null);
useEffect(() => {
if (!matchMedia("(hover: hover) and (pointer: fine)").matches) return;
const ball = ballRef.current, skin = skinRef.current;
if (!ball || !skin) return;
const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;
const R = num("--ml-ball-size", 30) / 2;
const STIFF = num("--ml-ball-stiffness", 900), DAMP = num("--ml-ball-damping", 52);
const GROW = num("--ml-ball-hot-scale", 1.35);
const S = { x: -100, y: -100, s: 1 }, V = { x: 0, y: 0, s: 0 }, G = { x: -100, y: -100, s: 1 };
let over = 1, down = false, raf = 0, last = 0, seen = false, spin = 0;
const step = (t: number) => {
// The first frame after a rest compares the frame time with performance.now(), which can be a
// little later: never step backwards, or the spring blows up.
const dt = Math.max(0, Math.min((t - last) / 1000, 1 / 30));
last = t;
G.s = over * (down ? 0.85 : 1);
const px = S.x, py = S.y;
let moving = false;
for (const [k, stiff, damp] of [["x", STIFF, DAMP], ["y", STIFF, DAMP], ["s", 320, 20]] as const) {
if (reduce) { S[k] = G[k]; continue; }
V[k] += (stiff * (G[k] - S[k]) - damp * V[k]) * dt;
S[k] += V[k] * dt;
if (Math.abs(V[k]) > 0.01 || Math.abs(G[k] - S[k]) > 0.01) moving = true;
}
// Roll: turn the seams by the arc travelled. Right spins clockwise; vertical travel adds a little.
if (!reduce) {
spin += ((S.x - px + (S.y - py) * 0.35) / R) * (180 / Math.PI);
skin.style.transform = `rotate(${spin}deg)`;
}
ball.style.transform = `translate(${S.x}px, ${S.y}px) scale(${S.s})`;
raf = moving ? requestAnimationFrame(step) : 0;
};
const kick = () => {
if (!raf) { last = performance.now(); raf = requestAnimationFrame(step); }
};
const onMove = (e: PointerEvent) => {
if (e.pointerType !== "mouse" && e.pointerType !== "pen") return;
G.x = e.clientX; G.y = e.clientY;
if (!seen) { S.x = G.x; S.y = G.y; seen = true; }
ball.setAttribute("data-on", "");
kick();
};
const onOver = (e: PointerEvent) => {
const isHot = !!(e.target as Element | null)?.closest?.(hot);
over = isHot ? GROW : 1;
ball.toggleAttribute("data-hot", isHot);
kick();
};
const onDown = () => { down = true; kick(); };
const onUp = () => { down = false; kick(); };
const onLeave = () => ball.removeAttribute("data-on");
// Modal dialogs and popovers live in the browser's top layer, above any z-index. The ball is a
// manual popover too, and steps back on top whenever one of them opens, so it is never hidden.
const toTop = () => {
if (!ball.isConnected) return;
if (ball.matches(":popover-open")) ball.hidePopover();
ball.showPopover();
};
toTop();
const onToggle = (e: Event) => {
if (e.target !== ball && (e as ToggleEvent).newState === "open") toTop();
};
const dialogs = new MutationObserver((list) => {
if (list.some((m) => (m.target as Element).matches("dialog[open]"))) toTop();
});
dialogs.observe(document.body, { attributes: true, attributeFilter: ["open"], subtree: true });
document.addEventListener("toggle", onToggle, true);
document.documentElement.classList.add("ml-has-ball");
addEventListener("pointermove", onMove, { passive: true });
document.addEventListener("pointerover", onOver);
addEventListener("pointerdown", onDown);
addEventListener("pointerup", onUp);
document.documentElement.addEventListener("pointerleave", onLeave);
return () => {
cancelAnimationFrame(raf);
dialogs.disconnect();
document.removeEventListener("toggle", onToggle, true);
if (ball.matches(":popover-open")) ball.hidePopover();
document.documentElement.classList.remove("ml-has-ball");
removeEventListener("pointermove", onMove);
document.removeEventListener("pointerover", onOver);
removeEventListener("pointerdown", onDown);
removeEventListener("pointerup", onUp);
document.documentElement.removeEventListener("pointerleave", onLeave);
};
}, [hot]);
return (
<div ref={ballRef} className="ml-ball ml-chrome" aria-hidden="true" popover="manual">
<span ref={skinRef} className="ml-chrome__skin">
<BallSeams />
</span>
</div>
);
}
/** The seam pattern that turns with the ball. Original design, no brand marks. */
export function BallSeams() {
return (
<svg viewBox="0 0 100 100" fill="none" stroke="oklch(0.3 0.01 260 / 0.75)" strokeWidth="3" strokeLinecap="round">
<path d="M50 34 L64 44 L59 61 L41 61 L36 44 Z" fill="oklch(0.3 0.01 260 / 0.55)" />
<path d="M50 34 C50 22 46 12 40 2" />
<path d="M64 44 C76 40 88 42 99 48" />
<path d="M59 61 C66 72 70 84 70 97" />
<path d="M41 61 C33 70 24 78 10 84" />
<path d="M36 44 C26 36 16 30 3 30" />
</svg>
);
}
/*
Rolling ball: a chrome football that replaces the pointer.
Three layers: the chrome base and the lamp light stay fixed, only the seams (the skin) turn,
so it reads as a 3D ball rolling under a light.
Fine pointers only. Reduced motion: follows the pointer directly, no roll, no spring.
*/
html.ml-has-ball,
html.ml-has-ball * {
cursor: none !important;
}
.ml-ball {
position: fixed;
inset: 0 auto auto 0;
/* it is a manual popover (to sit in the top layer above dialogs): undo the popover defaults */
border: 0;
padding: 0;
overflow: visible;
color: inherit;
z-index: 1000;
width: var(--ml-ball-size);
height: var(--ml-ball-size);
margin: calc(var(--ml-ball-size) / -2) 0 0 calc(var(--ml-ball-size) / -2);
border-radius: 50%;
pointer-events: none;
opacity: 0;
will-change: transform;
filter: drop-shadow(0 6px 8px oklch(0 0 0 / 0.28)) drop-shadow(0 1px 1px oklch(0 0 0 / 0.2));
transition: opacity var(--ml-dur-quick) var(--ml-ease-out);
}
/* The chrome ball itself, shared by the pointer and the logo mark */
.ml-chrome {
border-radius: 50%;
/* Chrome: cold reflections banded around the sphere, darker toward the rim */
background:
radial-gradient(circle at 50% 50%, transparent 55%, oklch(0.25 0 0 / 0.45) 100%),
conic-gradient(from 200deg at 45% 40%,
oklch(0.97 0 0), oklch(0.62 0.01 260), oklch(0.93 0 0), oklch(0.45 0.01 260),
oklch(0.88 0 0), oklch(0.7 0.01 260), oklch(0.97 0 0));
}
.ml-ball[data-on] {
opacity: 1;
}
.ml-chrome__skin {
position: absolute;
inset: 0;
border-radius: 50%;
overflow: hidden;
will-change: transform;
}
.ml-chrome__skin svg {
width: 100%;
height: 100%;
display: block;
}
/* The lamp: a fixed highlight top-left */
.ml-chrome::after {
content: "";
position: absolute;
inset: 0;
border-radius: 50%;
background: radial-gradient(circle at 34% 28%, oklch(1 0 0 / 0.7), transparent 38%);
}
/* Over something clickable: it stays solid chrome and grows (in JS), with a brighter lamp,
so the pointer state is the ball catching the light, never a native hand. */
.ml-ball[data-hot] {
opacity: 1;
}
.ml-ball.ml-chrome[data-hot]::after {
background: radial-gradient(circle at 34% 28%, oklch(1 0 0 / 0.95), transparent 44%);
}
