Custom cursor
A ring that trails the pointer with soft lag and changes character: it grows soft over links, narrows to a bar over text and picks up a label over buttons; a centre dot sits on the pointer with zero lag, and on touch — or when the mouse leaves — everything fades away.
Real scenarios
The component as it is used in a product — not a specimen grid.
Autumn drop · 04 · Kyoto
Wander the whole collectionTwelve pieces cut in Kyoto and Copenhagen — a coat that packs into its own pocket, wool knits dyed with tea, and boots that break in on the first walk. Move your pointer over this paragraph and the cursor thins into a reading bar.
Ring over the title, bar over the copy, label over the button — leave the stage and it all fades; on touch the native cursor stays.
Important props
| Prop | Type | Default | What it does |
|---|---|---|---|
| data-cursor | link · text · play | '' | The element under the pointer picks the ring’s state: link grows it, text thins it to a bar, play labels it; with neither you get the neutral ring. |
| --mfxcs-lag | number | 0.18 | The ring’s lerp factor; 0.18 closes 18% of the gap each frame — lower means looser. |
| label | string | null | The button’s data-label sits inside the ring; only for the play state. |
| pointer: coarse | media | 'hide' | On touch the ring is removed and the native cursor returns; leaving the stage fades everything out. |
| prefers-reduced-motion | behaviour | 'instant' | With reduced motion the lag is dropped and the follow is instant. |
Snippet
<div class="mfxcs" x-data="cursorFx()">
<div class="mfxcs-stage" x-ref="stage">
<a class="mfxcs-link" data-cursor="link" href="#drops">Explore the autumn drop</a>
<p class="mfxcs-copy" data-cursor="text">The ring trails the mouse; the dot does not.</p>
<button class="mfxcs-btn" data-cursor="play" data-label="Play">Play the trailer</button>
<span class="mfxcs-pos" x-ref="pos"><span class="mfxcs-ring"><span x-text="label"></span></span></span>
<span class="mfxcs-pos mfxcs-dot" x-ref="dot"></span>
</div>
</div>
<style>
.mfxcs-stage { position: relative; overflow: clip; cursor: none; }
.mfxcs-pos { position: absolute; inset-block-start: 0; inset-inline-start: 0; pointer-events: none; }
.mfxcs-ring { display: grid; place-items: center; translate: -50% -50%; inline-size: 18px; aspect-ratio: 1;
border: 1.5px solid #111; border-radius: 999px; transition: inline-size .18s, background-color .18s; }
.mfxcs[data-mode='link'] .mfxcs-ring { inline-size: 56px; background: #1111; }
.mfxcs[data-mode='text'] .mfxcs-ring { inline-size: 4px; block-size: 26px; border-radius: 2px; background: #111; }
.mfxcs[data-mode='play'] .mfxcs-ring { inline-size: 64px; background: #111; color: #fff; }
</style>
// app/Pages/Showcase.jsx — Inertia (React) page; renders the React
// snippet below unchanged, with Inertia's Link wired into the provider.
import { Link } from '@inertiajs/react';
import { NabuXUIProvider } from '@nabuxai/ui-react';
import CursorStage from '@/components/CursorStage';
export default function Showcase() {
return (
<NabuXUIProvider locale="en" linkComponent={Link}>
<main className="nx-page">
<CursorStage />
</main>
</NabuXUIProvider>
);
}
// CursorStage.jsx — the trailing cursor with states (link / text / play)
import { useEffect, useRef, useState } from 'react';
import '@nabuxai/ui-core/css';
export default function CursorStage() {
const stageRef = useRef(null);
const ringRef = useRef(null);
const dotRef = useRef(null);
const [label, setLabel] = useState('');
useEffect(() => {
const stage = stageRef.current, ring = ringRef.current, dot = dotRef.current;
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;
let raf = 0, tx = 0, ty = 0, rx = 0, ry = 0, rtl = false;
const place = (el, x, y) => { el.style.translate = `${rtl ? -x : x}px ${y}px`; };
const tick = () => {
const k = reduced ? 1 : 0.18; // the lag, dropped under reduced motion
rx += (tx - rx) * k; ry += (ty - ry) * k;
place(ring, rx, ry); place(dot, tx, ty); // the dot never lags
raf = requestAnimationFrame(tick);
};
const onMove = (e) => {
const r = stage.getBoundingClientRect();
const px = e.clientX - r.left, py = e.clientY - r.top;
rtl = getComputedStyle(stage).direction === 'rtl';
tx = rtl ? r.width - px : px; ty = py; // measure from the inline-start edge
const hit = e.target.closest('[data-cursor]');
stage.dataset.mode = hit?.dataset.cursor ?? '';
setLabel(hit?.dataset.label ?? '');
stage.dataset.on = 'yes';
};
const onLeave = () => { stage.dataset.on = 'no'; };
stage.addEventListener('pointermove', onMove);
stage.addEventListener('pointerover', onMove);
stage.addEventListener('pointerleave', onLeave);
raf = requestAnimationFrame(tick);
return () => {
cancelAnimationFrame(raf);
stage.removeEventListener('pointermove', onMove);
stage.removeEventListener('pointerover', onMove);
stage.removeEventListener('pointerleave', onLeave);
};
}, []);
return (
<>
<style>{`
.mfxcs-stage { position: relative; overflow: clip; cursor: none; min-block-size: 18rem;
display: grid; gap: 1rem; place-content: center; text-align: center;
border-radius: 1rem; background: #fafafa; }
.mfxcs-pos { position: absolute; inset-block-start: 0; inset-inline-start: 0; pointer-events: none;
opacity: 0; transition: opacity .2s; }
.mfxcs-stage[data-on='yes'] .mfxcs-pos { opacity: 1; }
.mfxcs-ring { display: grid; place-items: center; translate: -50% -50%; inline-size: 18px; aspect-ratio: 1;
border: 1.5px solid #111; border-radius: 999px; font: 500 .7rem/1 system-ui; color: #111;
transition: inline-size .18s, background-color .18s, color .18s; }
.mfxcs-dot { translate: -50% -50%; inline-size: 5px; aspect-ratio: 1; border-radius: 50%; background: #111; }
.mfxcs-stage[data-mode='link'] .mfxcs-ring { inline-size: 56px; background: #11100018; }
.mfxcs-stage[data-mode='text'] .mfxcs-ring { inline-size: 4px; block-size: 26px; border-radius: 2px; background: #111; }
.mfxcs-stage[data-mode='play'] .mfxcs-ring { inline-size: 64px; background: #111; color: #fff; }
@media (pointer: coarse) { .mfxcs-stage { cursor: auto; } .mfxcs-pos { display: none; } }
`}</style>
<div className="mfxcs-stage" ref={stageRef} data-on="no" data-mode="">
<a className="mfxcs-hit" data-cursor="link" href="#drops">Explore the autumn drop</a>
<p data-cursor="text">The ring trails the mouse; the dot does not.</p>
<button type="button" data-cursor="play" data-label="Play">Play the trailer</button>
<span className="mfxcs-pos" ref={ringRef}>
<span className="mfxcs-ring">{label}</span>
</span>
<span className="mfxcs-pos mfxcs-dot" ref={dotRef} />
</div>
</>
);
}
<!-- CursorStage.vue — the trailing cursor with states (link / text / play) -->
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from 'vue';
import '@nabuxai/ui-core/css';
const stage = ref<HTMLElement | null>(null);
const ring = ref<HTMLElement | null>(null);
const dot = ref<HTMLElement | null>(null);
const label = ref('');
let raf = 0, tx = 0, ty = 0, rx = 0, ry = 0, rtl = false, reduced = false;
const place = (el: HTMLElement, x: number, y: number) => { el.style.translate = `${rtl ? -x : x}px ${y}px`; };
const tick = () => {
const k = reduced ? 1 : 0.18; // the lag, dropped under reduced motion
rx += (tx - rx) * k; ry += (ty - ry) * k;
place(ring.value!, rx, ry); place(dot.value!, tx, ty); // the dot never lags
raf = requestAnimationFrame(tick);
};
const onMove = (e: PointerEvent) => {
const el = stage.value!, r = el.getBoundingClientRect();
const px = e.clientX - r.left, py = e.clientY - r.top;
rtl = getComputedStyle(el).direction === 'rtl';
tx = rtl ? r.width - px : px; ty = py; // measure from the inline-start edge
const hit = (e.target as Element).closest('[data-cursor]');
el.dataset.mode = hit?.getAttribute('data-cursor') ?? '';
label.value = hit?.getAttribute('data-label') ?? '';
el.dataset.on = 'yes';
};
const onLeave = () => { stage.value!.dataset.on = 'no'; };
onMounted(() => {
reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;
stage.value!.addEventListener('pointermove', onMove);
stage.value!.addEventListener('pointerover', onMove);
stage.value!.addEventListener('pointerleave', onLeave);
raf = requestAnimationFrame(tick);
});
onBeforeUnmount(() => {
cancelAnimationFrame(raf);
stage.value?.removeEventListener('pointermove', onMove);
stage.value?.removeEventListener('pointerover', onMove);
stage.value?.removeEventListener('pointerleave', onLeave);
});
</script>
<template>
<div ref="stage" class="mfxcs-stage" data-on="no" data-mode="">
<a data-cursor="link" href="#drops">Explore the autumn drop</a>
<p data-cursor="text">The ring trails the mouse; the dot does not.</p>
<button type="button" data-cursor="play" data-label="Play">Play the trailer</button>
<span ref="ring" class="mfxcs-pos"><span class="mfxcs-ring">{{ label }}</span></span>
<span ref="dot" class="mfxcs-pos mfxcs-dot"></span>
</div>
</template>
<style scoped>
.mfxcs-stage { position: relative; overflow: clip; cursor: none; min-block-size: 18rem;
display: grid; gap: 1rem; place-content: center; text-align: center;
border-radius: 1rem; background: #fafafa; }
.mfxcs-pos { position: absolute; inset-block-start: 0; inset-inline-start: 0; pointer-events: none;
opacity: 0; transition: opacity .2s; }
.mfxcs-stage[data-on='yes'] :deep(.mfxcs-pos) { opacity: 1; }
.mfxcs-ring { display: grid; place-items: center; translate: -50% -50%; inline-size: 18px; aspect-ratio: 1;
border: 1.5px solid #111; border-radius: 999px; font: 500 .7rem/1 system-ui; color: #111;
transition: inline-size .18s, background-color .18s, color .18s; }
.mfxcs-dot { translate: -50% -50%; inline-size: 5px; aspect-ratio: 1; border-radius: 50%; background: #111; }
.mfxcs-stage[data-mode='link'] :deep(.mfxcs-ring) { inline-size: 56px; background: #11100018; }
.mfxcs-stage[data-mode='text'] :deep(.mfxcs-ring) { inline-size: 4px; block-size: 26px; border-radius: 2px; background: #111; }
.mfxcs-stage[data-mode='play'] :deep(.mfxcs-ring) { inline-size: 64px; background: #111; color: #fff; }
@media (pointer: coarse) { .mfxcs-stage { cursor: auto; } .mfxcs-pos { display: none; } }
</style>
<!-- CursorStage.svelte — the trailing cursor with states (link / text / play) -->
<script lang="ts">
import { onMount } from 'svelte';
import '@nabuxai/ui-core/css';
let stage: HTMLElement, ring: HTMLElement, dot: HTMLElement;
let label = $state('');
let raf = 0, tx = 0, ty = 0, rx = 0, ry = 0, rtl = false, reduced = false;
const place = (el: HTMLElement, x: number, y: number) => { el.style.translate = `${rtl ? -x : x}px ${y}px`; };
const tick = () => {
const k = reduced ? 1 : 0.18; // the lag, dropped under reduced motion
rx += (tx - rx) * k; ry += (ty - ry) * k;
place(ring, rx, ry); place(dot, tx, ty); // the dot never lags
raf = requestAnimationFrame(tick);
};
const onMove = (e: PointerEvent) => {
const r = stage.getBoundingClientRect();
const px = e.clientX - r.left, py = e.clientY - r.top;
rtl = getComputedStyle(stage).direction === 'rtl';
tx = rtl ? r.width - px : px; ty = py; // measure from the inline-start edge
const hit = (e.target as Element).closest('[data-cursor]');
stage.dataset.mode = hit?.getAttribute('data-cursor') ?? '';
label = hit?.getAttribute('data-label') ?? '';
stage.dataset.on = 'yes';
};
const onLeave = () => { stage.dataset.on = 'no'; };
onMount(() => {
reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;
stage.addEventListener('pointermove', onMove);
stage.addEventListener('pointerover', onMove);
stage.addEventListener('pointerleave', onLeave);
raf = requestAnimationFrame(tick);
return () => {
cancelAnimationFrame(raf);
stage.removeEventListener('pointermove', onMove);
stage.removeEventListener('pointerover', onMove);
stage.removeEventListener('pointerleave', onLeave);
};
});
</script>
<div bind:this={stage} class="mfxcs-stage" data-on="no" data-mode="">
<a data-cursor="link" href="#drops">Explore the autumn drop</a>
<p data-cursor="text">The ring trails the mouse; the dot does not.</p>
<button type="button" data-cursor="play" data-label="Play">Play the trailer</button>
<span bind:this={ring} class="mfxcs-pos"><span class="mfxcs-ring">{label}</span></span>
<span bind:this={dot} class="mfxcs-pos mfxcs-dot"></span>
</div>
<style>
.mfxcs-stage { position: relative; overflow: clip; cursor: none; min-block-size: 18rem;
display: grid; gap: 1rem; place-content: center; text-align: center;
border-radius: 1rem; background: #fafafa; }
.mfxcs-pos { position: absolute; inset-block-start: 0; inset-inline-start: 0; pointer-events: none;
opacity: 0; transition: opacity .2s; }
.mfxcs-stage[data-on='yes'] .mfxcs-pos { opacity: 1; }
.mfxcs-ring { display: grid; place-items: center; translate: -50% -50%; inline-size: 18px; aspect-ratio: 1;
border: 1.5px solid #111; border-radius: 999px; font: 500 .7rem/1 system-ui; color: #111;
transition: inline-size .18s, background-color .18s, color .18s; }
.mfxcs-dot { translate: -50% -50%; inline-size: 5px; aspect-ratio: 1; border-radius: 50%; background: #111; }
.mfxcs-stage[data-mode='link'] .mfxcs-ring { inline-size: 56px; background: #11100018; }
.mfxcs-stage[data-mode='text'] .mfxcs-ring { inline-size: 4px; block-size: 26px; border-radius: 2px; background: #111; }
.mfxcs-stage[data-mode='play'] .mfxcs-ring { inline-size: 64px; background: #111; color: #fff; }
@media (pointer: coarse) { .mfxcs-stage { cursor: auto; } .mfxcs-pos { display: none; } }
</style>