Comet
A bright head whose tail stretches out as you speed up. It swells inside a faint coma over controls.
npx shadcn@latest add https://hoverui.fun/ r/ comet.jsonAdds components/cursors/comet.tsx. The CLI also installs the useCursor hook it runs on, once, into your hooks folder. The files are yours from there.
Move through the preview, then hover the controls and press.Open this on a computer to move it around: it follows a mouse, not a finger.
- Kind
- Space
- Hook
- useCursor
- Dependencies
- None
- License
- MIT
How it behaves
A bright head with a tail that stretches out behind you as you speed up; over a control the head swells inside a faint coma.
Usage
import { CometCursor } from "@/components/cursors/comet";
export function Section() {
return (
<section>
<CometCursor />
{/* this section now wears Comet */}
</section>
);
}Put it inside <body> in your root layout to wear it on every page. Nested cursors take over inside their own element.
Props
- className
- Colors the cursor through currentColor, e.g. text-pink-500. To read on any background, pass text-white mix-blend-difference, as this site does.
- Hover targets
- a, button, input, select, textarea, label, [role=button], [data-cursor-label]
Source
"use client";
import { useRef } from "react";
import { cursorRoot, useCursor } from "@/hooks/use-cursor";
const TAIL = 180;
/** A bright head with a tail that stretches out behind you as you speed up; over a control the head swells inside a faint coma. */
export function CometCursor({ className = "" }: { className?: string }) {
const s = useRef({ x: 0, y: 0, len: 0, angle: 0, size: 1, coma: 0 });
const ref = useCursor((p, el) => {
const st = s.current;
const vx = p.dt ? (p.x - st.x) / p.dt : 0;
const vy = p.dt ? (p.y - st.y) / p.dt : 0;
[st.x, st.y] = [p.x, p.y];
const speed = Math.hypot(vx, vy);
if (speed > 30) st.angle = Math.atan2(vy, vx);
st.len += ((p.reduced ? 0 : Math.min(speed * 0.12, TAIL)) - st.len) * p.ease(10);
st.size += ((p.down ? 0.7 : p.hover ? 1.6 : 1) - st.size) * p.ease(16);
st.coma += ((p.hover ? 1 : 0) - st.coma) * p.ease(10);
const [tail, coma, head] = el.children as HTMLCollectionOf<HTMLElement>;
tail.style.transform = `translate(${p.x}px, ${p.y}px) rotate(${st.angle + Math.PI}rad) scaleX(${st.len / TAIL})`;
coma.style.transform = `translate(${p.x}px, ${p.y}px) scale(${st.coma})`;
head.style.transform = `translate(${p.x}px, ${p.y}px) scale(${st.size})`;
});
return (
<div ref={ref} aria-hidden className={`${cursorRoot} ${className}`}>
<div className="absolute top-[-3px] left-0 h-1.5 origin-left rounded-full bg-linear-to-r from-current to-transparent" style={{ width: TAIL }} />
<div className="absolute size-9 -translate-1/2 rounded-full bg-current opacity-20" />
<div className="absolute size-2.5 -translate-1/2 rounded-full bg-current" />
</div>
);
}
It runs on the useCursor hook, which has its own source and API.
More space cursors
- OrbitA moon circling the pointer. Its orbit widens over anything clickable.
- RocketThe nose is the pointer. It turns to face where you go; the engine roars over controls and cuts on press.
- AstronautDrifts behind the pointer on a slack tether, bobbing in zero gravity. Reels itself in over controls.
- UFOA saucer hovering above the pointer. Over anything clickable, it lowers a tractor beam onto it.
- ConstellationDraws a constellation as you move, star by star, fading out behind you. A click sets a bright one.
- Black holeBends the page round it like a lens and swallows dust from your path. Swells over controls; hold, and time slows.
- GalaxyA spiral galaxy turning round the pointer, its arms trailing as you move. Over controls the stars trace the outline; press for a supernova.
Made a cursor of your own? Contributed cursors carry their maker's name on their page.
Contribute a cursor