Components101 / 118
Hover Menu
Big editorial navigation. The row you point at rolls its letters over into an italic serif in its own colour while the rest dim, a hairline fills and the arrow swings into a disc. A photograph rides your cursor on a soft spring, drawn on the GPU: it bends like a sheet against your motion, stretches with speed and melts from one picture into the next as you move down the list.
GSAPGSAPthree.jsthree.jsReal linksReal linksKeyboard friendlyKeyboard friendly60fps60fpsReduced-motion safeReduced-motion safe
Glide up and down the list
Tweak
LIVELIVERow colours
#4a74ff
#ff6b3d
#b27cff
#ffc53d
Image
240px
1.00
Usage
Follows your tweaks.
usage.tsx
import { HoverMenu } from "@/components/inreact/hover-menu";
const items = [
{ label: "Work", meta: "24 projects", href: "/work", image: "/images/work.jpg", accent: "#4a74ff" },
{ label: "Studio", meta: "Since 2019", href: "/studio", image: "/images/studio.jpg", accent: "#ff6b3d" },
{ label: "Journal", meta: "Notes & essays", href: "/journal", image: "/images/journal.jpg", accent: "#b27cff" },
{ label: "Contact", meta: "Say hello", href: "/contact", image: "/images/contact.jpg", accent: "#ffc53d" },
];
export function SiteMenu() {
return <HoverMenu items={items} hoverFont="'Instrument Serif', Georgia, serif" className="w-full max-w-3xl" />;
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/hover-menu.jsonTS + CSS
npx shadcn@latest add https://inreact.vercel.app/r/hover-menu-css.jsonOr copy the source
Install the dependencies, then save this as components/inreact/hover-menu.tsx.
terminal
npm install gsap threecomponents/inreact/hover-menu.tsx
"use client";
import { gsap } from "gsap";
import * as THREE from "three";
import { useEffect, useLayoutEffect, useRef, type CSSProperties } from "react";
/**
* Hover Menu: big editorial navigation with a living image that follows you.
*
* Point at a row and its letters roll over one by one, from the plain face into
* an italic serif in that row's own colour, with a small dip first and an
* overshoot as they land; the other rows dim, a hairline fills under the row
* and the arrow swings round into a filled disc. A photograph rides your
* cursor on a soft spring, rendered on the GPU: it bends like a sheet against
* your motion, stretches with your speed, splits its colours a little when you
* move fast, and melts from one picture to the next as you move down the list.
* It pops in with an overshoot and winds up before it leaves.
*
* <HoverMenu items={[{ label: "Work", meta: "24 projects", href: "/work", image: "/work.jpg", accent: "#3d6bff" }]} />
*
* Real links; keyboard focus works like hover; reduced motion swaps without
* rolling or bending. On touch screens the image sits beside the tapped row.
*/
export interface HoverMenuItem {
label: string;
/** Short line on the right of the row. */
meta?: string;
href?: string;
/** Picture that follows the cursor over this row. */
image?: string;
/** This row's colour (rolled letters, hairline, arrow disc). */
accent?: string;
}
export interface HoverMenuProps {
items?: HoverMenuItem[];
/** Colour for rows without their own accent. */
accent?: string;
/** Width of the following image, px (4:5). */
imageWidth?: number;
/** How much the image bends and leans with your movement, 0 to 2. */
tilt?: number;
/** Font of the rows at rest. */
font?: string;
/** Font the letters roll into (shown in italic). */
hoverFont?: string;
/** Called when a row is clicked; return false to cancel navigation. */
onSelect?: (item: HoverMenuItem, index: number) => boolean | void;
className?: string;
}
const ITEMS: HoverMenuItem[] = [
{ label: "Work", meta: "24 projects", href: "#work", image: "/media/menu-work.webp", accent: "#4a74ff" },
{ label: "Studio", meta: "Since 2019", href: "#studio", image: "/media/menu-studio.webp", accent: "#ff6b3d" },
{ label: "Journal", meta: "Notes & essays", href: "#journal", image: "/media/menu-journal.webp", accent: "#b27cff" },
{ label: "Contact", meta: "Say hello", href: "#contact", image: "/media/menu-contact.webp", accent: "#ffc53d" },
];
const INK = "#f4f1ea";
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const finePointer = () => typeof window !== "undefined" && window.matchMedia("(pointer: fine)").matches;
const clamp = (a: number, b: number, v: number) => Math.max(a, Math.min(b, v));
const VERT = /* glsl */ `
uniform vec2 uPos, uSize, uVel;
uniform float uScale, uBend, uAngle, uStretch;
varying vec2 vUv;
void main() {
vUv = uv;
// the camera's y axis points down (css px), so flip the sheet to keep pictures upright
vec2 p = vec2(position.x, -position.y) * uSize * uScale;
// the sheet bends against the motion: its middle lags behind its edges
p -= uVel * uBend * 0.02 * (sin(uv.y * 3.14159) * vec2(1.0, 0.0) + sin(uv.x * 3.14159) * vec2(0.0, 1.0));
// squash and stretch along the direction of travel (volume kept)
float c = cos(uAngle), s = sin(uAngle);
vec2 q = vec2(c * p.x + s * p.y, -s * p.x + c * p.y);
q *= vec2(uStretch, 1.0 / sqrt(uStretch));
p = vec2(c * q.x - s * q.y, s * q.x + c * q.y);
// a lean into the motion
float lean = clamp(uVel.x * 0.00008 * uBend, -0.12, 0.12);
p = vec2(cos(lean) * p.x - sin(lean) * p.y, sin(lean) * p.x + cos(lean) * p.y);
gl_Position = projectionMatrix * modelViewMatrix * vec4(uPos + p, 0.0, 1.0);
}`;
const FRAG = /* glsl */ `
uniform sampler2D uA, uB;
uniform vec2 uSize, uVel, uAspA, uAspB;
uniform float uMix, uScale, uAlpha, uTime, uRadius, uZoom;
uniform vec3 uColA, uColB;
uniform float uHasA, uHasB;
varying vec2 vUv;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float noise(vec2 p) {
vec2 i = floor(p), f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1, 0)), u.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), u.x), u.y);
}
// object-fit: cover inside the sheet, with a slow zoom and a drift against the motion
vec2 cover(vec2 uv, vec2 asp) {
vec2 s = asp; // (planeAspect / texAspect) folded into a scale per axis
return (uv - 0.5) * s / uZoom + 0.5 - uVel * 0.00003;
}
vec3 pick(sampler2D t, vec2 uv, vec2 asp, vec3 fallback, float has) {
if (has < 0.5) return fallback;
vec2 k = uVel * 0.000012; // colour split with speed (a few px at most)
vec2 c = cover(uv, asp);
return vec3(texture2D(t, c + k).r, texture2D(t, c).g, texture2D(t, c - k).b);
}
void main() {
// rounded corners
vec2 px = (vUv - 0.5) * uSize;
vec2 q = abs(px) - (uSize * 0.5 - uRadius);
float d = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - uRadius;
float a = (1.0 - smoothstep(-0.8, 0.8, d)) * uAlpha;
if (a < 0.002) discard;
// the next picture melts in through a moving, noisy front
float n = noise(vUv * 3.5 + uTime * 0.25) * 0.65 + noise(vUv * 11.0 - uTime * 0.4) * 0.35;
float front = smoothstep(uMix * 1.35 - 0.3, uMix * 1.35 - 0.05, n + (1.0 - vUv.y) * 0.3);
float wob = sin(3.14159 * uMix) * 0.05;
vec2 duv = vUv + (n - 0.5) * wob;
vec3 A = pick(uA, duv, uAspA, uColA, uHasA);
vec3 B = pick(uB, duv, uAspB, uColB, uHasB);
vec3 col = mix(B, A, front);
gl_FragColor = vec4(col * a, a);
}`;
export function HoverMenu({ items = ITEMS, accent = "#4a74ff", imageWidth = 240, tilt = 1, font, hoverFont, onSelect, className }: HoverMenuProps) {
const rootRef = useRef<HTMLElement>(null);
const holderRef = useRef<HTMLDivElement>(null);
const tiltRef = useRef(tilt);
tiltRef.current = tilt;
const api = useRef({ show: (_i: number, _x?: number, _y?: number) => {}, hide: () => {} });
const accentOf = (i: number) => items[i]?.accent ?? accent;
// ---- the rows: rolling letters, dimming, hairline, arrow ----
const active = useRef(-1);
const rollTl = useRef(new Map<number, gsap.core.Timeline>());
const setRow = (i: number) => {
const root = rootRef.current;
if (!root || i === active.current) return;
const still = reduced();
const prev = active.current;
active.current = i;
const rows = root.querySelectorAll<HTMLElement>("[data-row]");
rows.forEach((row, k) => {
const on = k === i;
const was = k === prev;
const dim = i >= 0 && !on;
gsap.to(row, { opacity: dim ? 0.3 : 1, duration: 0.45, ease: "power2.out", overwrite: "auto" });
if (!on && !was) return;
const base = row.querySelectorAll("[data-a]"), alt = row.querySelectorAll("[data-b]");
const line = row.querySelector("[data-line]"), disc = row.querySelector("[data-disc]"), arrow = row.querySelector("[data-arrow]");
const idx = row.querySelector("[data-idx]"), meta = row.querySelector("[data-meta]");
// one timeline per row, replaced on every change, so a quick pass never leaves letters half-rolled
rollTl.current.get(k)?.kill();
const tl = gsap.timeline();
rollTl.current.set(k, tl);
if (still) {
gsap.set(base, { yPercent: on ? -110 : 0 });
gsap.set(alt, { yPercent: on ? 0 : 110, rotate: 0 });
} else if (on) {
// anticipation: a small dip, then over the top with an overshoot
tl.to(base, { yPercent: 12, duration: 0.08, ease: "power1.out", stagger: 0.02 }, 0)
.to(base, { yPercent: -112, duration: 0.5, ease: "power3.in", stagger: 0.02 }, 0.05)
.fromTo(alt, { yPercent: 110, rotate: 8 }, { yPercent: 0, rotate: 0, duration: 0.72, ease: "back.out(1.9)", stagger: 0.022 }, 0.04);
} else {
tl.to(alt, { yPercent: -110, rotate: 0, duration: 0.35, ease: "power2.in", stagger: 0.012 }, 0)
.fromTo(base, { yPercent: 110 }, { yPercent: 0, duration: 0.55, ease: "back.out(1.6)", stagger: 0.012 }, 0.02);
}
const col = on ? accentOf(k) : INK;
gsap.to(line, { scaleX: on ? 1 : 0, transformOrigin: on ? "0% 50%" : "100% 50%", duration: still ? 0 : on ? 0.8 : 0.45, ease: on ? "expo.out" : "power2.in", overwrite: true });
gsap.to(disc, { scale: on ? 1 : 0, duration: still ? 0 : on ? 0.6 : 0.3, ease: on ? "back.out(2.6)" : "power2.in", overwrite: true });
gsap.to(arrow, { rotate: on ? 0 : -45, color: on ? "#0b0b0c" : INK, duration: still ? 0 : 0.6, ease: "back.out(3)", overwrite: true });
gsap.to(idx, { color: on ? col : "rgba(244,241,234,.45)", duration: 0.3, overwrite: true });
gsap.to(meta, { x: on ? -10 : 0, color: on ? INK : "rgba(244,241,234,.5)", duration: still ? 0 : 0.6, ease: "back.out(2)", overwrite: true });
});
};
// the italic letters wait below the line until a row is chosen
useLayoutEffect(() => {
const root = rootRef.current;
if (!root) return;
gsap.set(root.querySelectorAll("[data-b]"), { yPercent: 110 });
active.current = -1;
}, [items.map((i) => i.label).join("|")]); // eslint-disable-line react-hooks/exhaustive-deps
// ---- the image: one three.js sheet that follows the cursor ----
useEffect(() => {
const root = rootRef.current, holder = holderRef.current;
if (!root || !holder) return;
const still = reduced();
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true, premultipliedAlpha: true });
} catch {
return; // no WebGL: the rows still work, just without the image
}
const canvas = renderer.domElement;
canvas.setAttribute("aria-hidden", "true");
Object.assign(canvas.style, { position: "absolute", pointerEvents: "none", left: "0", top: "0" });
holder.appendChild(canvas);
renderer.setClearColor(0x000000, 0);
const scene = new THREE.Scene();
const cam = new THREE.OrthographicCamera(0, 1, 0, 1, -10, 10);
const W0 = imageWidth, H0 = Math.round(imageWidth * 1.25);
const loader = new THREE.TextureLoader();
const tex: (THREE.Texture | null)[] = items.map(() => null);
const asp: [number, number][] = items.map(() => [1, 1]);
const coverScale = (iw: number, ih: number): [number, number] => {
const pa = W0 / H0, ta = iw / ih;
return pa > ta ? [1, ta / pa] : [pa / ta, 1];
};
items.forEach((it, i) => {
if (!it.image) return;
loader.load(it.image, (t) => {
t.colorSpace = THREE.NoColorSpace;
t.minFilter = THREE.LinearMipmapLinearFilter;
t.anisotropy = renderer.capabilities.getMaxAnisotropy();
tex[i] = t;
const img = t.image as HTMLImageElement;
asp[i] = coverScale(img.width, img.height);
wake();
});
});
const hexCol = (c: string) => new THREE.Color(c);
const U = {
uPos: { value: new THREE.Vector2() },
uSize: { value: new THREE.Vector2(W0, H0) },
uVel: { value: new THREE.Vector2() },
uScale: { value: 0 },
uBend: { value: 1 },
uAngle: { value: 0 },
uStretch: { value: 1 },
uA: { value: null as THREE.Texture | null },
uB: { value: null as THREE.Texture | null },
uAspA: { value: new THREE.Vector2(1, 1) },
uAspB: { value: new THREE.Vector2(1, 1) },
uColA: { value: hexCol(accent) },
uColB: { value: hexCol(accent) },
uHasA: { value: 0 },
uHasB: { value: 0 },
uMix: { value: 1 },
uAlpha: { value: 0 },
uTime: { value: 0 },
uRadius: { value: Math.round(W0 * 0.06) },
uZoom: { value: 1 },
};
const mat = new THREE.ShaderMaterial({ uniforms: U, vertexShader: VERT, fragmentShader: FRAG, transparent: true, side: THREE.DoubleSide, depthTest: false });
mat.blending = THREE.CustomBlending;
mat.blendSrc = THREE.OneFactor;
mat.blendDst = THREE.OneMinusSrcAlphaFactor;
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(1, 1, 28, 28), mat);
scene.add(mesh);
// canvas covers the menu plus room for the image to spill past its edges
let M = 0, CW = 0, CH = 0;
const resize = () => {
M = Math.round(Math.max(W0, H0) * 0.75);
CW = root.clientWidth + M * 2;
CH = root.clientHeight + M * 2;
renderer.setPixelRatio(Math.min(2, window.devicePixelRatio || 1));
renderer.setSize(CW, CH, false);
Object.assign(canvas.style, { left: `${-M}px`, top: `${-M}px`, width: `${CW}px`, height: `${CH}px` });
cam.right = CW;
cam.bottom = CH;
cam.updateProjectionMatrix();
wake();
};
// state: position spring (slightly underdamped, so it overshoots and settles), scale and alpha tweens
const s = { x: 0, y: 0, vx: 0, vy: 0, tx: 0, ty: 0, shown: false, cur: -1 };
const look = { scale: 0, alpha: 0, mix: 1, zoom: 1 };
let awake = 0;
const wake = () => (awake = 4);
const setTex = (slot: "A" | "B", i: number) => {
const t = i >= 0 ? tex[i] : null;
U[`u${slot}`].value = t;
U[`uHas${slot}`].value = t ? 1 : 0;
const k = i >= 0 ? asp[i] : [1, 1];
(U[`uAsp${slot}`].value as THREE.Vector2).set(k[0], k[1]);
(U[`uCol${slot}`].value as THREE.Color).set(i >= 0 ? accentOf(i) : accent);
};
api.current.show = (i, x, y) => {
const r = root.getBoundingClientRect();
const z = r.width / Math.max(1, root.offsetWidth); // the menu may be scaled (zoom / transform)
const lx = x === undefined ? root.clientWidth * 0.66 : (x - r.left) / z;
const rows = root.querySelectorAll<HTMLElement>("[data-row]");
const row = rows[i];
const ly = y === undefined ? (row ? row.offsetTop + row.offsetHeight / 2 : root.clientHeight / 2) : (y - r.top) / z;
s.tx = lx + M + W0 * 0.12;
s.ty = ly + M;
if (!s.shown) {
s.x = s.tx;
s.y = s.ty;
s.vx = s.vy = 0;
s.shown = true;
setTex("A", i);
setTex("B", i);
look.mix = 1;
gsap.killTweensOf(look);
if (still) Object.assign(look, { scale: 1, alpha: 1, zoom: 1 });
else {
gsap.fromTo(look, { scale: 0.35 }, { scale: 1, duration: 0.7, ease: "back.out(1.7)" });
gsap.to(look, { alpha: 1, duration: 0.25, ease: "power1.out" });
gsap.fromTo(look, { zoom: 1.35 }, { zoom: 1.08, duration: 1.1, ease: "expo.out" });
}
s.cur = i;
} else if (i !== s.cur) {
// melt from the picture on screen into the next one
setTex("A", s.cur);
setTex("B", i);
s.cur = i;
if (still) look.mix = 1;
else {
gsap.fromTo(look, { mix: 0 }, { mix: 1, duration: 0.85, ease: "power2.out", overwrite: false });
gsap.fromTo(look, { zoom: 1.2 }, { zoom: 1.08, duration: 0.9, ease: "expo.out" });
}
}
wake();
};
api.current.hide = () => {
if (!s.shown) return;
s.shown = false;
gsap.killTweensOf(look, "scale,alpha");
if (still) Object.assign(look, { scale: 0, alpha: 0 });
else
gsap
.timeline()
.to(look, { scale: 1.06, duration: 0.12, ease: "power1.out" }) // wind up
.to(look, { scale: 0.3, alpha: 0, duration: 0.38, ease: "power3.in" });
wake();
};
const onMove = (e: PointerEvent) => {
if (!s.shown) return;
const r = root.getBoundingClientRect();
const z = r.width / Math.max(1, root.offsetWidth);
s.tx = (e.clientX - r.left) / z + M + W0 * 0.12;
s.ty = (e.clientY - r.top) / z + M;
// a jump (a touch landing elsewhere, a scripted cursor) moves the picture there instead of flinging it across
if (Math.hypot(s.tx - s.x, s.ty - s.y) > W0 * 1.6) (s.x = s.tx), (s.y = s.ty), (s.vx = s.vy = 0);
wake();
};
// only movement over this menu steers the picture (never other pointers or demo cursors elsewhere on the page)
root.addEventListener("pointermove", onMove, { passive: true });
let visible = true;
const io = new IntersectionObserver(([en]) => (visible = en.isIntersecting));
io.observe(root);
const ro = new ResizeObserver(resize);
ro.observe(root);
resize();
const tick = (time: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
if (!visible) return;
if (still) (s.x = s.tx), (s.y = s.ty), (s.vx = s.vy = 0);
else
for (let k = 0; k < 2; k++) {
const h = dt / 2;
s.vx += (190 * (s.tx - s.x) - 19 * s.vx) * h;
s.vy += (190 * (s.ty - s.y) - 19 * s.vy) * h;
s.x += s.vx * h;
s.y += s.vy * h;
}
const moving = Math.abs(s.vx) + Math.abs(s.vy) > 1 || gsap.isTweening(look);
if (moving || look.alpha > 0.001) awake = Math.max(awake, moving ? 4 : 1);
if (awake <= 0) return;
awake--;
const sp = Math.hypot(s.vx, s.vy);
const bend = clamp(0, 2, tiltRef.current);
U.uPos.value.set(s.x, s.y);
// velocity as seen by the shader is bounded, so the sheet stays elegant at any speed
const vmax = 1500, vs = sp > vmax ? vmax / sp : 1;
U.uVel.value.set(s.vx * vs, s.vy * vs);
U.uBend.value = bend;
U.uAngle.value = Math.atan2(s.vy, s.vx);
U.uStretch.value = 1 + Math.min(0.14, (Math.min(sp, vmax) / 6000) * bend);
U.uScale.value = look.scale;
U.uAlpha.value = look.alpha;
U.uMix.value = look.mix;
U.uZoom.value = look.zoom;
U.uTime.value = time;
mesh.visible = look.alpha > 0.002 && look.scale > 0.01;
renderer.render(scene, cam);
};
gsap.ticker.add(tick);
return () => {
gsap.ticker.remove(tick);
root.removeEventListener("pointermove", onMove);
io.disconnect();
ro.disconnect();
gsap.killTweensOf(look);
api.current.show = () => {};
api.current.hide = () => {};
tex.forEach((t) => t?.dispose());
mesh.geometry.dispose();
mat.dispose();
renderer.dispose();
renderer.forceContextLoss();
canvas.remove();
};
}, [items.map((i) => `${i.image}|${i.accent}`).join(","), imageWidth, accent]); // eslint-disable-line react-hooks/exhaustive-deps
// hover intent: a row only reacts once the pointer rests on it for a moment,
// so sweeping across the list doesn't flick every word on the way
const intent = useRef(0);
const lastPt = useRef<{ clientX: number; clientY: number } | null>(null);
useEffect(() => () => window.clearTimeout(intent.current), []);
const enter = (i: number, e?: { clientX: number; clientY: number }, now = false) => {
window.clearTimeout(intent.current);
lastPt.current = e ? { clientX: e.clientX, clientY: e.clientY } : null;
const go = () => {
setRow(i);
const pt = lastPt.current;
api.current.show(i, pt?.clientX, pt?.clientY);
};
if (now || reduced()) go();
else intent.current = window.setTimeout(go, 70);
};
const leave = () => {
window.clearTimeout(intent.current);
setRow(-1);
api.current.hide();
};
const chars = (t: string, attr: "data-a" | "data-b", style: CSSProperties) =>
[...t].map((ch, k) => (
<span key={k} {...{ [attr]: "" }} style={{ display: "inline-block", willChange: "transform", ...style }}>
{ch === " " ? " " : ch}
</span>
));
const serif = hoverFont ?? 'var(--font-instrument, "Instrument Serif"), Georgia, "Times New Roman", serif';
return (
<nav
ref={rootRef}
aria-label="Main"
className={["relative", className].filter(Boolean).join(" ")}
style={{ containerType: "inline-size", fontFamily: font, color: INK }}
onPointerLeave={(e) => e.pointerType === "mouse" && leave()}
>
<ul style={{ listStyle: "none", margin: 0, padding: 0 }}>
{items.map((it, i) => {
const col = accentOf(i);
return (
<li key={it.label} data-row style={{ position: "relative" }}>
<a
href={it.href ?? "#"}
onPointerEnter={(e) => e.pointerType === "mouse" && finePointer() && enter(i, e)}
onPointerDown={(e) => e.pointerType !== "mouse" && enter(i, undefined, true)}
onPointerMove={(e) => (lastPt.current = { clientX: e.clientX, clientY: e.clientY })}
onFocus={() => enter(i, undefined, true)}
onBlur={(e) => !rootRef.current?.contains(e.relatedTarget as Node | null) && leave()}
onClick={(e) => {
if (onSelect?.(it, i) === false) e.preventDefault();
}}
style={{
display: "flex",
alignItems: "center",
gap: "clamp(10px, 2.4cqw, 22px)",
padding: "clamp(10px, 2.2cqw, 20px) 0",
color: "inherit",
textDecoration: "none",
outline: "none",
cursor: "pointer",
}}
>
<span data-idx style={{ fontFamily: 'var(--font-jetbrains, ui-monospace), ui-monospace, monospace', fontSize: "clamp(10px, 1.5cqw, 13px)", color: "rgba(244,241,234,.45)", width: "2.4em", flexShrink: 0, alignSelf: "flex-start", marginTop: "0.9em" }}>
{String(i + 1).padStart(2, "0")}
</span>
{/* the word: plain letters roll up and away, italic serif letters roll in */}
<span aria-hidden="true" style={{ position: "relative", display: "block", overflow: "hidden", fontSize: "clamp(30px, 10cqw, 92px)", lineHeight: 1, letterSpacing: "-0.035em", fontWeight: 500, padding: "0.06em 0.18em 0.1em 0", margin: "-0.06em 0 -0.1em" }}>
<span style={{ display: "block", whiteSpace: "nowrap" }}>{chars(it.label, "data-a", {})}</span>
<span style={{ position: "absolute", left: 0, top: "0.06em", whiteSpace: "nowrap", fontFamily: serif, fontStyle: "italic", fontWeight: 400, letterSpacing: "-0.01em", color: col }}>
{chars(it.label, "data-b", {})}
</span>
</span>
<span style={{ position: "absolute", width: 1, height: 1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap" }}>{it.label}</span>
<span style={{ flex: 1 }} />
{it.meta && (
<span data-meta style={{ fontSize: "clamp(11px, 1.7cqw, 15px)", color: "rgba(244,241,234,.5)", whiteSpace: "nowrap" }}>
{it.meta}
</span>
)}
<span style={{ position: "relative", display: "grid", placeItems: "center", width: "clamp(30px, 5.4cqw, 46px)", aspectRatio: "1", flexShrink: 0 }}>
<span data-disc style={{ position: "absolute", inset: 0, borderRadius: 999, background: col, transform: "scale(0)" }} />
<svg data-arrow viewBox="0 0 24 24" width="46%" height="46%" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" style={{ position: "relative", transform: "rotate(-45deg)" }}>
<path d="M5 12h14M13 6l6 6-6 6" />
</svg>
</span>
</a>
<span aria-hidden="true" style={{ position: "absolute", left: 0, right: 0, bottom: 0, height: 1, background: "rgba(244,241,234,.12)" }} />
<span data-line aria-hidden="true" style={{ position: "absolute", left: 0, right: 0, bottom: 0, height: 1, background: col, transform: "scaleX(0)", transformOrigin: "0% 50%" }} />
</li>
);
})}
</ul>
<div ref={holderRef} aria-hidden="true" style={{ position: "absolute", inset: 0, pointerEvents: "none", zIndex: 5 }} />
</nav>
);
}
export default HoverMenu;
›Plain CSS variant (no Tailwind)
components/inreact/hover-menu.tsx
"use client";
import { gsap } from "gsap";
import * as THREE from "three";
import { useEffect, useLayoutEffect, useRef, type CSSProperties } from "react";
import "./hover-menu.css";
/**
* Hover Menu: big editorial navigation with a living image that follows you.
*
* Point at a row and its letters roll over one by one, from the plain face into
* an italic serif in that row's own colour, with a small dip first and an
* overshoot as they land; the other rows dim, a hairline fills under the row
* and the arrow swings round into a filled disc. A photograph rides your
* cursor on a soft spring, rendered on the GPU: it bends like a sheet against
* your motion, stretches with your speed, splits its colours a little when you
* move fast, and melts from one picture to the next as you move down the list.
* It pops in with an overshoot and winds up before it leaves.
*
* <HoverMenu items={[{ label: "Work", meta: "24 projects", href: "/work", image: "/work.jpg", accent: "#3d6bff" }]} />
*
* Real links; keyboard focus works like hover; reduced motion swaps without
* rolling or bending. On touch screens the image sits beside the tapped row.
*/
export interface HoverMenuItem {
label: string;
/** Short line on the right of the row. */
meta?: string;
href?: string;
/** Picture that follows the cursor over this row. */
image?: string;
/** This row's colour (rolled letters, hairline, arrow disc). */
accent?: string;
}
export interface HoverMenuProps {
items?: HoverMenuItem[];
/** Colour for rows without their own accent. */
accent?: string;
/** Width of the following image, px (4:5). */
imageWidth?: number;
/** How much the image bends and leans with your movement, 0 to 2. */
tilt?: number;
/** Font of the rows at rest. */
font?: string;
/** Font the letters roll into (shown in italic). */
hoverFont?: string;
/** Called when a row is clicked; return false to cancel navigation. */
onSelect?: (item: HoverMenuItem, index: number) => boolean | void;
className?: string;
}
const ITEMS: HoverMenuItem[] = [
{ label: "Work", meta: "24 projects", href: "#work", image: "/media/menu-work.webp", accent: "#4a74ff" },
{ label: "Studio", meta: "Since 2019", href: "#studio", image: "/media/menu-studio.webp", accent: "#ff6b3d" },
{ label: "Journal", meta: "Notes & essays", href: "#journal", image: "/media/menu-journal.webp", accent: "#b27cff" },
{ label: "Contact", meta: "Say hello", href: "#contact", image: "/media/menu-contact.webp", accent: "#ffc53d" },
];
const INK = "#f4f1ea";
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const finePointer = () => typeof window !== "undefined" && window.matchMedia("(pointer: fine)").matches;
const clamp = (a: number, b: number, v: number) => Math.max(a, Math.min(b, v));
const VERT = /* glsl */ `
uniform vec2 uPos, uSize, uVel;
uniform float uScale, uBend, uAngle, uStretch;
varying vec2 vUv;
void main() {
vUv = uv;
// the camera's y axis points down (css px), so flip the sheet to keep pictures upright
vec2 p = vec2(position.x, -position.y) * uSize * uScale;
// the sheet bends against the motion: its middle lags behind its edges
p -= uVel * uBend * 0.02 * (sin(uv.y * 3.14159) * vec2(1.0, 0.0) + sin(uv.x * 3.14159) * vec2(0.0, 1.0));
// squash and stretch along the direction of travel (volume kept)
float c = cos(uAngle), s = sin(uAngle);
vec2 q = vec2(c * p.x + s * p.y, -s * p.x + c * p.y);
q *= vec2(uStretch, 1.0 / sqrt(uStretch));
p = vec2(c * q.x - s * q.y, s * q.x + c * q.y);
// a lean into the motion
float lean = clamp(uVel.x * 0.00008 * uBend, -0.12, 0.12);
p = vec2(cos(lean) * p.x - sin(lean) * p.y, sin(lean) * p.x + cos(lean) * p.y);
gl_Position = projectionMatrix * modelViewMatrix * vec4(uPos + p, 0.0, 1.0);
}`;
const FRAG = /* glsl */ `
uniform sampler2D uA, uB;
uniform vec2 uSize, uVel, uAspA, uAspB;
uniform float uMix, uScale, uAlpha, uTime, uRadius, uZoom;
uniform vec3 uColA, uColB;
uniform float uHasA, uHasB;
varying vec2 vUv;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float noise(vec2 p) {
vec2 i = floor(p), f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1, 0)), u.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), u.x), u.y);
}
// object-fit: cover inside the sheet, with a slow zoom and a drift against the motion
vec2 cover(vec2 uv, vec2 asp) {
vec2 s = asp; // (planeAspect / texAspect) folded into a scale per axis
return (uv - 0.5) * s / uZoom + 0.5 - uVel * 0.00003;
}
vec3 pick(sampler2D t, vec2 uv, vec2 asp, vec3 fallback, float has) {
if (has < 0.5) return fallback;
vec2 k = uVel * 0.000012; // colour split with speed (a few px at most)
vec2 c = cover(uv, asp);
return vec3(texture2D(t, c + k).r, texture2D(t, c).g, texture2D(t, c - k).b);
}
void main() {
// rounded corners
vec2 px = (vUv - 0.5) * uSize;
vec2 q = abs(px) - (uSize * 0.5 - uRadius);
float d = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - uRadius;
float a = (1.0 - smoothstep(-0.8, 0.8, d)) * uAlpha;
if (a < 0.002) discard;
// the next picture melts in through a moving, noisy front
float n = noise(vUv * 3.5 + uTime * 0.25) * 0.65 + noise(vUv * 11.0 - uTime * 0.4) * 0.35;
float front = smoothstep(uMix * 1.35 - 0.3, uMix * 1.35 - 0.05, n + (1.0 - vUv.y) * 0.3);
float wob = sin(3.14159 * uMix) * 0.05;
vec2 duv = vUv + (n - 0.5) * wob;
vec3 A = pick(uA, duv, uAspA, uColA, uHasA);
vec3 B = pick(uB, duv, uAspB, uColB, uHasB);
vec3 col = mix(B, A, front);
gl_FragColor = vec4(col * a, a);
}`;
export function HoverMenu({ items = ITEMS, accent = "#4a74ff", imageWidth = 240, tilt = 1, font, hoverFont, onSelect, className }: HoverMenuProps) {
const rootRef = useRef<HTMLElement>(null);
const holderRef = useRef<HTMLDivElement>(null);
const tiltRef = useRef(tilt);
tiltRef.current = tilt;
const api = useRef({ show: (_i: number, _x?: number, _y?: number) => {}, hide: () => {} });
const accentOf = (i: number) => items[i]?.accent ?? accent;
// ---- the rows: rolling letters, dimming, hairline, arrow ----
const active = useRef(-1);
const rollTl = useRef(new Map<number, gsap.core.Timeline>());
const setRow = (i: number) => {
const root = rootRef.current;
if (!root || i === active.current) return;
const still = reduced();
const prev = active.current;
active.current = i;
const rows = root.querySelectorAll<HTMLElement>("[data-row]");
rows.forEach((row, k) => {
const on = k === i;
const was = k === prev;
const dim = i >= 0 && !on;
gsap.to(row, { opacity: dim ? 0.3 : 1, duration: 0.45, ease: "power2.out", overwrite: "auto" });
if (!on && !was) return;
const base = row.querySelectorAll("[data-a]"), alt = row.querySelectorAll("[data-b]");
const line = row.querySelector("[data-line]"), disc = row.querySelector("[data-disc]"), arrow = row.querySelector("[data-arrow]");
const idx = row.querySelector("[data-idx]"), meta = row.querySelector("[data-meta]");
// one timeline per row, replaced on every change, so a quick pass never leaves letters half-rolled
rollTl.current.get(k)?.kill();
const tl = gsap.timeline();
rollTl.current.set(k, tl);
if (still) {
gsap.set(base, { yPercent: on ? -110 : 0 });
gsap.set(alt, { yPercent: on ? 0 : 110, rotate: 0 });
} else if (on) {
// anticipation: a small dip, then over the top with an overshoot
tl.to(base, { yPercent: 12, duration: 0.08, ease: "power1.out", stagger: 0.02 }, 0)
.to(base, { yPercent: -112, duration: 0.5, ease: "power3.in", stagger: 0.02 }, 0.05)
.fromTo(alt, { yPercent: 110, rotate: 8 }, { yPercent: 0, rotate: 0, duration: 0.72, ease: "back.out(1.9)", stagger: 0.022 }, 0.04);
} else {
tl.to(alt, { yPercent: -110, rotate: 0, duration: 0.35, ease: "power2.in", stagger: 0.012 }, 0)
.fromTo(base, { yPercent: 110 }, { yPercent: 0, duration: 0.55, ease: "back.out(1.6)", stagger: 0.012 }, 0.02);
}
const col = on ? accentOf(k) : INK;
gsap.to(line, { scaleX: on ? 1 : 0, transformOrigin: on ? "0% 50%" : "100% 50%", duration: still ? 0 : on ? 0.8 : 0.45, ease: on ? "expo.out" : "power2.in", overwrite: true });
gsap.to(disc, { scale: on ? 1 : 0, duration: still ? 0 : on ? 0.6 : 0.3, ease: on ? "back.out(2.6)" : "power2.in", overwrite: true });
gsap.to(arrow, { rotate: on ? 0 : -45, color: on ? "#0b0b0c" : INK, duration: still ? 0 : 0.6, ease: "back.out(3)", overwrite: true });
gsap.to(idx, { color: on ? col : "rgba(244,241,234,.45)", duration: 0.3, overwrite: true });
gsap.to(meta, { x: on ? -10 : 0, color: on ? INK : "rgba(244,241,234,.5)", duration: still ? 0 : 0.6, ease: "back.out(2)", overwrite: true });
});
};
// the italic letters wait below the line until a row is chosen
useLayoutEffect(() => {
const root = rootRef.current;
if (!root) return;
gsap.set(root.querySelectorAll("[data-b]"), { yPercent: 110 });
active.current = -1;
}, [items.map((i) => i.label).join("|")]); // eslint-disable-line react-hooks/exhaustive-deps
// ---- the image: one three.js sheet that follows the cursor ----
useEffect(() => {
const root = rootRef.current, holder = holderRef.current;
if (!root || !holder) return;
const still = reduced();
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true, premultipliedAlpha: true });
} catch {
return; // no WebGL: the rows still work, just without the image
}
const canvas = renderer.domElement;
canvas.setAttribute("aria-hidden", "true");
Object.assign(canvas.style, { position: "absolute", pointerEvents: "none", left: "0", top: "0" });
holder.appendChild(canvas);
renderer.setClearColor(0x000000, 0);
const scene = new THREE.Scene();
const cam = new THREE.OrthographicCamera(0, 1, 0, 1, -10, 10);
const W0 = imageWidth, H0 = Math.round(imageWidth * 1.25);
const loader = new THREE.TextureLoader();
const tex: (THREE.Texture | null)[] = items.map(() => null);
const asp: [number, number][] = items.map(() => [1, 1]);
const coverScale = (iw: number, ih: number): [number, number] => {
const pa = W0 / H0, ta = iw / ih;
return pa > ta ? [1, ta / pa] : [pa / ta, 1];
};
items.forEach((it, i) => {
if (!it.image) return;
loader.load(it.image, (t) => {
t.colorSpace = THREE.NoColorSpace;
t.minFilter = THREE.LinearMipmapLinearFilter;
t.anisotropy = renderer.capabilities.getMaxAnisotropy();
tex[i] = t;
const img = t.image as HTMLImageElement;
asp[i] = coverScale(img.width, img.height);
wake();
});
});
const hexCol = (c: string) => new THREE.Color(c);
const U = {
uPos: { value: new THREE.Vector2() },
uSize: { value: new THREE.Vector2(W0, H0) },
uVel: { value: new THREE.Vector2() },
uScale: { value: 0 },
uBend: { value: 1 },
uAngle: { value: 0 },
uStretch: { value: 1 },
uA: { value: null as THREE.Texture | null },
uB: { value: null as THREE.Texture | null },
uAspA: { value: new THREE.Vector2(1, 1) },
uAspB: { value: new THREE.Vector2(1, 1) },
uColA: { value: hexCol(accent) },
uColB: { value: hexCol(accent) },
uHasA: { value: 0 },
uHasB: { value: 0 },
uMix: { value: 1 },
uAlpha: { value: 0 },
uTime: { value: 0 },
uRadius: { value: Math.round(W0 * 0.06) },
uZoom: { value: 1 },
};
const mat = new THREE.ShaderMaterial({ uniforms: U, vertexShader: VERT, fragmentShader: FRAG, transparent: true, side: THREE.DoubleSide, depthTest: false });
mat.blending = THREE.CustomBlending;
mat.blendSrc = THREE.OneFactor;
mat.blendDst = THREE.OneMinusSrcAlphaFactor;
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(1, 1, 28, 28), mat);
scene.add(mesh);
// canvas covers the menu plus room for the image to spill past its edges
let M = 0, CW = 0, CH = 0;
const resize = () => {
M = Math.round(Math.max(W0, H0) * 0.75);
CW = root.clientWidth + M * 2;
CH = root.clientHeight + M * 2;
renderer.setPixelRatio(Math.min(2, window.devicePixelRatio || 1));
renderer.setSize(CW, CH, false);
Object.assign(canvas.style, { left: `${-M}px`, top: `${-M}px`, width: `${CW}px`, height: `${CH}px` });
cam.right = CW;
cam.bottom = CH;
cam.updateProjectionMatrix();
wake();
};
// state: position spring (slightly underdamped, so it overshoots and settles), scale and alpha tweens
const s = { x: 0, y: 0, vx: 0, vy: 0, tx: 0, ty: 0, shown: false, cur: -1 };
const look = { scale: 0, alpha: 0, mix: 1, zoom: 1 };
let awake = 0;
const wake = () => (awake = 4);
const setTex = (slot: "A" | "B", i: number) => {
const t = i >= 0 ? tex[i] : null;
U[`u${slot}`].value = t;
U[`uHas${slot}`].value = t ? 1 : 0;
const k = i >= 0 ? asp[i] : [1, 1];
(U[`uAsp${slot}`].value as THREE.Vector2).set(k[0], k[1]);
(U[`uCol${slot}`].value as THREE.Color).set(i >= 0 ? accentOf(i) : accent);
};
api.current.show = (i, x, y) => {
const r = root.getBoundingClientRect();
const z = r.width / Math.max(1, root.offsetWidth); // the menu may be scaled (zoom / transform)
const lx = x === undefined ? root.clientWidth * 0.66 : (x - r.left) / z;
const rows = root.querySelectorAll<HTMLElement>("[data-row]");
const row = rows[i];
const ly = y === undefined ? (row ? row.offsetTop + row.offsetHeight / 2 : root.clientHeight / 2) : (y - r.top) / z;
s.tx = lx + M + W0 * 0.12;
s.ty = ly + M;
if (!s.shown) {
s.x = s.tx;
s.y = s.ty;
s.vx = s.vy = 0;
s.shown = true;
setTex("A", i);
setTex("B", i);
look.mix = 1;
gsap.killTweensOf(look);
if (still) Object.assign(look, { scale: 1, alpha: 1, zoom: 1 });
else {
gsap.fromTo(look, { scale: 0.35 }, { scale: 1, duration: 0.7, ease: "back.out(1.7)" });
gsap.to(look, { alpha: 1, duration: 0.25, ease: "power1.out" });
gsap.fromTo(look, { zoom: 1.35 }, { zoom: 1.08, duration: 1.1, ease: "expo.out" });
}
s.cur = i;
} else if (i !== s.cur) {
// melt from the picture on screen into the next one
setTex("A", s.cur);
setTex("B", i);
s.cur = i;
if (still) look.mix = 1;
else {
gsap.fromTo(look, { mix: 0 }, { mix: 1, duration: 0.85, ease: "power2.out", overwrite: false });
gsap.fromTo(look, { zoom: 1.2 }, { zoom: 1.08, duration: 0.9, ease: "expo.out" });
}
}
wake();
};
api.current.hide = () => {
if (!s.shown) return;
s.shown = false;
gsap.killTweensOf(look, "scale,alpha");
if (still) Object.assign(look, { scale: 0, alpha: 0 });
else
gsap
.timeline()
.to(look, { scale: 1.06, duration: 0.12, ease: "power1.out" }) // wind up
.to(look, { scale: 0.3, alpha: 0, duration: 0.38, ease: "power3.in" });
wake();
};
const onMove = (e: PointerEvent) => {
if (!s.shown) return;
const r = root.getBoundingClientRect();
const z = r.width / Math.max(1, root.offsetWidth);
s.tx = (e.clientX - r.left) / z + M + W0 * 0.12;
s.ty = (e.clientY - r.top) / z + M;
// a jump (a touch landing elsewhere, a scripted cursor) moves the picture there instead of flinging it across
if (Math.hypot(s.tx - s.x, s.ty - s.y) > W0 * 1.6) (s.x = s.tx), (s.y = s.ty), (s.vx = s.vy = 0);
wake();
};
// only movement over this menu steers the picture (never other pointers or demo cursors elsewhere on the page)
root.addEventListener("pointermove", onMove, { passive: true });
let visible = true;
const io = new IntersectionObserver(([en]) => (visible = en.isIntersecting));
io.observe(root);
const ro = new ResizeObserver(resize);
ro.observe(root);
resize();
const tick = (time: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
if (!visible) return;
if (still) (s.x = s.tx), (s.y = s.ty), (s.vx = s.vy = 0);
else
for (let k = 0; k < 2; k++) {
const h = dt / 2;
s.vx += (190 * (s.tx - s.x) - 19 * s.vx) * h;
s.vy += (190 * (s.ty - s.y) - 19 * s.vy) * h;
s.x += s.vx * h;
s.y += s.vy * h;
}
const moving = Math.abs(s.vx) + Math.abs(s.vy) > 1 || gsap.isTweening(look);
if (moving || look.alpha > 0.001) awake = Math.max(awake, moving ? 4 : 1);
if (awake <= 0) return;
awake--;
const sp = Math.hypot(s.vx, s.vy);
const bend = clamp(0, 2, tiltRef.current);
U.uPos.value.set(s.x, s.y);
// velocity as seen by the shader is bounded, so the sheet stays elegant at any speed
const vmax = 1500, vs = sp > vmax ? vmax / sp : 1;
U.uVel.value.set(s.vx * vs, s.vy * vs);
U.uBend.value = bend;
U.uAngle.value = Math.atan2(s.vy, s.vx);
U.uStretch.value = 1 + Math.min(0.14, (Math.min(sp, vmax) / 6000) * bend);
U.uScale.value = look.scale;
U.uAlpha.value = look.alpha;
U.uMix.value = look.mix;
U.uZoom.value = look.zoom;
U.uTime.value = time;
mesh.visible = look.alpha > 0.002 && look.scale > 0.01;
renderer.render(scene, cam);
};
gsap.ticker.add(tick);
return () => {
gsap.ticker.remove(tick);
root.removeEventListener("pointermove", onMove);
io.disconnect();
ro.disconnect();
gsap.killTweensOf(look);
api.current.show = () => {};
api.current.hide = () => {};
tex.forEach((t) => t?.dispose());
mesh.geometry.dispose();
mat.dispose();
renderer.dispose();
renderer.forceContextLoss();
canvas.remove();
};
}, [items.map((i) => `${i.image}|${i.accent}`).join(","), imageWidth, accent]); // eslint-disable-line react-hooks/exhaustive-deps
// hover intent: a row only reacts once the pointer rests on it for a moment,
// so sweeping across the list doesn't flick every word on the way
const intent = useRef(0);
const lastPt = useRef<{ clientX: number; clientY: number } | null>(null);
useEffect(() => () => window.clearTimeout(intent.current), []);
const enter = (i: number, e?: { clientX: number; clientY: number }, now = false) => {
window.clearTimeout(intent.current);
lastPt.current = e ? { clientX: e.clientX, clientY: e.clientY } : null;
const go = () => {
setRow(i);
const pt = lastPt.current;
api.current.show(i, pt?.clientX, pt?.clientY);
};
if (now || reduced()) go();
else intent.current = window.setTimeout(go, 70);
};
const leave = () => {
window.clearTimeout(intent.current);
setRow(-1);
api.current.hide();
};
const chars = (t: string, attr: "data-a" | "data-b", style: CSSProperties) =>
[...t].map((ch, k) => (
<span key={k} {...{ [attr]: "" }} style={{ display: "inline-block", willChange: "transform", ...style }}>
{ch === " " ? " " : ch}
</span>
));
const serif = hoverFont ?? 'var(--font-instrument, "Instrument Serif"), Georgia, "Times New Roman", serif';
return (
<nav
ref={rootRef}
aria-label="Main"
className={["hover-menu", className].filter(Boolean).join(" ")}
style={{ containerType: "inline-size", fontFamily: font, color: INK }}
onPointerLeave={(e) => e.pointerType === "mouse" && leave()}
>
<ul style={{ listStyle: "none", margin: 0, padding: 0 }}>
{items.map((it, i) => {
const col = accentOf(i);
return (
<li key={it.label} data-row style={{ position: "relative" }}>
<a
href={it.href ?? "#"}
onPointerEnter={(e) => e.pointerType === "mouse" && finePointer() && enter(i, e)}
onPointerDown={(e) => e.pointerType !== "mouse" && enter(i, undefined, true)}
onPointerMove={(e) => (lastPt.current = { clientX: e.clientX, clientY: e.clientY })}
onFocus={() => enter(i, undefined, true)}
onBlur={(e) => !rootRef.current?.contains(e.relatedTarget as Node | null) && leave()}
onClick={(e) => {
if (onSelect?.(it, i) === false) e.preventDefault();
}}
style={{
display: "flex",
alignItems: "center",
gap: "clamp(10px, 2.4cqw, 22px)",
padding: "clamp(10px, 2.2cqw, 20px) 0",
color: "inherit",
textDecoration: "none",
outline: "none",
cursor: "pointer",
}}
>
<span data-idx style={{ fontFamily: 'var(--font-jetbrains, ui-monospace), ui-monospace, monospace', fontSize: "clamp(10px, 1.5cqw, 13px)", color: "rgba(244,241,234,.45)", width: "2.4em", flexShrink: 0, alignSelf: "flex-start", marginTop: "0.9em" }}>
{String(i + 1).padStart(2, "0")}
</span>
{/* the word: plain letters roll up and away, italic serif letters roll in */}
<span aria-hidden="true" style={{ position: "relative", display: "block", overflow: "hidden", fontSize: "clamp(30px, 10cqw, 92px)", lineHeight: 1, letterSpacing: "-0.035em", fontWeight: 500, padding: "0.06em 0.18em 0.1em 0", margin: "-0.06em 0 -0.1em" }}>
<span style={{ display: "block", whiteSpace: "nowrap" }}>{chars(it.label, "data-a", {})}</span>
<span style={{ position: "absolute", left: 0, top: "0.06em", whiteSpace: "nowrap", fontFamily: serif, fontStyle: "italic", fontWeight: 400, letterSpacing: "-0.01em", color: col }}>
{chars(it.label, "data-b", {})}
</span>
</span>
<span style={{ position: "absolute", width: 1, height: 1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap" }}>{it.label}</span>
<span style={{ flex: 1 }} />
{it.meta && (
<span data-meta style={{ fontSize: "clamp(11px, 1.7cqw, 15px)", color: "rgba(244,241,234,.5)", whiteSpace: "nowrap" }}>
{it.meta}
</span>
)}
<span style={{ position: "relative", display: "grid", placeItems: "center", width: "clamp(30px, 5.4cqw, 46px)", aspectRatio: "1", flexShrink: 0 }}>
<span data-disc style={{ position: "absolute", inset: 0, borderRadius: 999, background: col, transform: "scale(0)" }} />
<svg data-arrow viewBox="0 0 24 24" width="46%" height="46%" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" style={{ position: "relative", transform: "rotate(-45deg)" }}>
<path d="M5 12h14M13 6l6 6-6 6" />
</svg>
</span>
</a>
<span aria-hidden="true" style={{ position: "absolute", left: 0, right: 0, bottom: 0, height: 1, background: "rgba(244,241,234,.12)" }} />
<span data-line aria-hidden="true" style={{ position: "absolute", left: 0, right: 0, bottom: 0, height: 1, background: col, transform: "scaleX(0)", transformOrigin: "0% 50%" }} />
</li>
);
})}
</ul>
<div ref={holderRef} aria-hidden="true" style={{ position: "absolute", inset: 0, pointerEvents: "none", zIndex: 5 }} />
</nav>
);
}
export default HoverMenu;
components/inreact/hover-menu.css
.hover-menu {
position: relative;
}
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
8 propsitemsHoverMenuItem[]Rows: label, meta, href, image (the picture that follows the cursor) and accent (the row's colour).default Work, Studio, Journal, Contactdefault Work, Studio, Journal, ContactaccentstringColour for rows without their own accent.default "#4a74ff"default "#4a74ff"imageWidthnumberWidth of the following image, px (4:5).default 240default 240tiltnumberHow much the image bends and leans with your movement, 0 to 2.default 1default 1fontstringFont of the rows at rest (inherits by default).hoverFontstringFont the letters roll into, shown in italic.default "Instrument Serif", Georgiadefault "Instrument Serif", GeorgiaonSelect(item, index) => boolean | voidCalled on click; return false to cancel navigation.classNamestringWidth and spacing of the menu.