Live preview · fully interactive
The prompt
Build a following ring cursor. ## Look A 54px circle with a 1.5px #c4b5fd border, centered on its point with a negative margin. Page is #08080d. ## Behavior Lerp the ring toward the pointer at 0.18 per frame. On pointer down add a class that scales the ring to 0.72; release removes it. ## Design tokens - Border #c4b5fd; page #08080d; hint #8a8a99. ## Motion - Follow lerp 0.18 per frame. Press scale transition 160ms ease. ## Constraints - Single self-contained HTML file. No libraries. - Honor prefers-reduced-motion: reduce by skipping the loop and leaving a readable static frame - Readable at 390px width with no horizontal page scroll
The code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { min-height: 100%; }
body {
background: #08080d; color: #f2f2f7; font-family: Inter, system-ui, sans-serif;
min-height: 100vh; overflow: hidden;
}
.hint { position: absolute; left: 16px; top: 16px; z-index: 5; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: #8a8a99; }
#ring { position: fixed; width: 54px; height: 54px; margin: -27px 0 0 -27px; border: 1.5px solid #c4b5fd; border-radius: 50%; pointer-events: none; transition: transform 160ms ease; } body.down #ring { transform: scale(0.72); }
@media (max-width: 420px) {
.hint { font-size: 10px; letter-spacing: 0.08em; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
</style>
</head>
<body>
<p class="hint">Press to tighten</p><div id="ring"></div>
<script>
var reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
var pointer = { x: window.innerWidth / 2, y: window.innerHeight / 2 };
var userMoved = false;
window.addEventListener("pointermove", function (e) {
userMoved = true;
pointer.x = e.clientX;
pointer.y = e.clientY;
});
function idlePointer(now) {
if (userMoved || reduce) return;
pointer.x = window.innerWidth * (0.5 + Math.cos(now / 700) * 0.28);
pointer.y = window.innerHeight * (0.5 + Math.sin(now / 900) * 0.2);
}
var ring = document.getElementById("ring");
var x = pointer.x, y = pointer.y;
window.addEventListener("pointerdown", function () { document.body.classList.add("down"); });
window.addEventListener("pointerup", function () { document.body.classList.remove("down"); });
function frame(now) {
if (reduce) { ring.style.left = pointer.x + "px"; ring.style.top = pointer.y + "px"; return; }
idlePointer(now);
x += (pointer.x - x) * 0.18;
y += (pointer.y - y) * 0.18;
ring.style.left = x + "px";
ring.style.top = y + "px";
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
</script>
</body>
</html>About this effect
A 54px ring follows the pointer with a damped ease. Pointer down scales it to 0.72 for 160ms. Useful as a custom cursor layer over a marketing page.