Scroll-speed marquee
Rows of huge words that react to how fast you scroll: they speed up, lean and blur with the motion, and you can grab a row and throw it.
"use client";
import { useEffect, useRef, type CSSProperties } from "react";
import "./velocity-marquee.css";
/**
* VelocityMarquee: rows of huge words that answer how fast you move.
* - Scroll the page or the wheel over it and the rows speed up, lean into the motion and stretch.
* - Grab a row and throw it: it keeps sliding with momentum, then settles back to its calm drift.
* - Rows go opposite ways and the star between words spins with the speed.
*/
export function VelocityMarquee({
rows,
theme = "dark",
}: {
rows: string[][];
theme?: "light" | "dark";
}) {
const root = useRef<HTMLDivElement>(null);
useEffect(() => {
const el = root.current!;
const reduce = window.matchMedia(
"(prefers-reduced-motion: reduce)",
).matches;
if (reduce) return;
const tracks = [...el.querySelectorAll<HTMLElement>(".gu-vmq__track")];
const state = tracks.map((_, i) => ({
x: 0,
v: 0,
dir: i % 2 ? 1 : -1,
held: false,
lastX: 0,
}));
let boost = 0;
let lastY = window.scrollY;
let raf = 0;
let last = performance.now();
const onScroll = () => {
const y = window.scrollY;
boost += (y - lastY) * 0.6;
lastY = y;
};
const onWheel = (e: WheelEvent) => {
boost += e.deltaY * 0.35;
};
window.addEventListener("scroll", onScroll, { passive: true });
el.addEventListener("wheel", onWheel, { passive: true });
const downs = tracks.map((t, i) => {
const down = (e: PointerEvent) => {
const s = state[i];
s.held = true;
s.lastX = e.clientX;
s.v = 0;
t.setPointerCapture(e.pointerId);
t.dataset.held = "true";
};
const move = (e: PointerEvent) => {
const s = state[i];
if (!s.held) return;
const dx = e.clientX - s.lastX;
s.lastX = e.clientX;
s.x += dx;
s.v = dx * 60;
};
const up = () => {
state[i].held = false;
t.dataset.held = "false";
};
t.addEventListener("pointerdown", down);
t.addEventListener("pointermove", move);
t.addEventListener("pointerup", up);
t.addEventListener("pointercancel", up);
return () => {
t.removeEventListener("pointerdown", down);
t.removeEventListener("pointermove", move);
t.removeEventListener("pointerup", up);
t.removeEventListener("pointercancel", up);
};
});
const loop = (now: number) => {
const dt = Math.min(0.05, (now - last) / 1000);
last = now;
boost *= 0.9;
tracks.forEach((t, i) => {
const s = state[i];
const half = t.scrollWidth / 2;
if (!s.held) {
// Calm drift plus whatever speed the scroll or a throw added, easing back to calm.
const target = s.dir * 60 + s.dir * boost * 8;
s.v += (target - s.v) * 0.06;
s.x += s.v * dt;
}
if (half > 0) {
s.x = ((s.x % half) - half) % half;
}
const speed = Math.max(-1, Math.min(1, s.v / 1800));
t.style.transform = `translate3d(${s.x}px,0,0) skewX(${-speed * 14}deg) scaleY(${1 - Math.abs(speed) * 0.08})`;
t.style.setProperty(
"--spin",
`${(now / 1000) * (90 + Math.abs(s.v) * 0.6)}deg`,
);
t.style.setProperty("--blur", `${Math.abs(speed) * 1.6}px`);
});
raf = requestAnimationFrame(loop);
};
raf = requestAnimationFrame(loop);
return () => {
cancelAnimationFrame(raf);
window.removeEventListener("scroll", onScroll);
el.removeEventListener("wheel", onWheel);
downs.forEach((off) => off());
};
}, [rows]);
return (
<div className="gu-vmq" data-theme={theme} ref={root}>
<p className="gu-vmq__sr">{rows.map((r) => r.join(", ")).join(". ")}</p>
{rows.map((words, i) => (
<div
key={i}
className="gu-vmq__row"
data-row={i % 3}
aria-hidden="true"
>
<div className="gu-vmq__track">
{[0, 1].map((copy) => (
<div key={copy} className="gu-vmq__set">
{[...words, ...words].map((w, j) => (
<span
key={j}
className="gu-vmq__item"
style={{ "--j": j } as CSSProperties}
>
<span className="gu-vmq__word">{w}</span>
<svg className="gu-vmq__star" viewBox="0 0 24 24">
<path d="M12 1.5c.8 5.6 4.9 9.7 10.5 10.5-5.6.8-9.7 4.9-10.5 10.5-.8-5.6-4.9-9.7-10.5-10.5C7.1 11.2 11.2 7.1 12 1.5Z" />
</svg>
</span>
))}
</div>
))}
</div>
</div>
))}
<p className="gu-vmq__hint" aria-hidden="true">
Scroll, or grab a row and throw it
</p>
</div>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Scroll-speed marquee
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
Three rows of huge words that drift sideways in opposite directions and react to speed. Scrolling the page (or the mouse wheel over it) makes them rush, lean into the motion, stretch and blur slightly; when you stop they ease back to a calm drift. Any row can be grabbed and thrown sideways. A four-point star sits between words and spins faster the faster the row goes.
## Layout and look
- Full width, radius 28px, padding 36px top. Dark #0e0e10 with cream #f3eee3 words (light: the reverse).
- Words clamp(44px, 8vw, 104px), weight 900, line-height 1, letter-spacing −0.045em.
- Row 1: plain with orange stars. Row 2: an orange #ff5a1f band with ink text, rotated −2deg, slightly wider than the box. Row 3: outlined words (transparent fill, 1.5px text stroke).
- A small hint at the bottom: "Scroll, or grab a row and throw it" (13px, 55% opacity).
## Behavior and motion
1. Each row's content is repeated twice so it can wrap seamlessly: x = ((x mod half) − half) mod half, where half is half the track width.
2. One requestAnimationFrame loop. Every row has velocity v (px/s); its target is direction × (60 + boost × 8), and v eases toward it by 6% per frame.
3. boost gets scroll delta × 0.6 and wheel delta × 0.35 and decays by 10% per frame.
4. Speed = clamp(v / 1800, −1, 1) gives skewX(−speed × 14deg), scaleY(1 − |speed| × 0.08) and blur(|speed| × 1.6px). The star rotates at 90 + |v| × 0.6 degrees per second.
5. Drag: pointer capture, the row follows the finger; on release its velocity is the last move × 60 and it slows back to its drift. touch-action: pan-y so vertical page scrolling still works.
## Accessibility
- Rows are aria-hidden; a visually hidden paragraph lists the words once.
- prefers-reduced-motion: no loop at all, rows wrap onto several lines and stay still.
## Props
rows (string[][]: the words of each row), theme.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### VelocityMarquee.tsx
```tsx
"use client";
import { useEffect, useRef, type CSSProperties } from "react";
import "./velocity-marquee.css";
/**
* VelocityMarquee: rows of huge words that answer how fast you move.
* - Scroll the page or the wheel over it and the rows speed up, lean into the motion and stretch.
* - Grab a row and throw it: it keeps sliding with momentum, then settles back to its calm drift.
* - Rows go opposite ways and the star between words spins with the speed.
*/
export function VelocityMarquee({
rows,
theme = "dark",
}: {
rows: string[][];
theme?: "light" | "dark";
}) {
const root = useRef<HTMLDivElement>(null);
useEffect(() => {
const el = root.current!;
const reduce = window.matchMedia(
"(prefers-reduced-motion: reduce)",
).matches;
if (reduce) return;
const tracks = [...el.querySelectorAll<HTMLElement>(".gu-vmq__track")];
const state = tracks.map((_, i) => ({
x: 0,
v: 0,
dir: i % 2 ? 1 : -1,
held: false,
lastX: 0,
}));
let boost = 0;
let lastY = window.scrollY;
let raf = 0;
let last = performance.now();
const onScroll = () => {
const y = window.scrollY;
boost += (y - lastY) * 0.6;
lastY = y;
};
const onWheel = (e: WheelEvent) => {
boost += e.deltaY * 0.35;
};
window.addEventListener("scroll", onScroll, { passive: true });
el.addEventListener("wheel", onWheel, { passive: true });
const downs = tracks.map((t, i) => {
const down = (e: PointerEvent) => {
const s = state[i];
s.held = true;
s.lastX = e.clientX;
s.v = 0;
t.setPointerCapture(e.pointerId);
t.dataset.held = "true";
};
const move = (e: PointerEvent) => {
const s = state[i];
if (!s.held) return;
const dx = e.clientX - s.lastX;
s.lastX = e.clientX;
s.x += dx;
s.v = dx * 60;
};
const up = () => {
state[i].held = false;
t.dataset.held = "false";
};
t.addEventListener("pointerdown", down);
t.addEventListener("pointermove", move);
t.addEventListener("pointerup", up);
t.addEventListener("pointercancel", up);
return () => {
t.removeEventListener("pointerdown", down);
t.removeEventListener("pointermove", move);
t.removeEventListener("pointerup", up);
t.removeEventListener("pointercancel", up);
};
});
const loop = (now: number) => {
const dt = Math.min(0.05, (now - last) / 1000);
last = now;
boost *= 0.9;
tracks.forEach((t, i) => {
const s = state[i];
const half = t.scrollWidth / 2;
if (!s.held) {
// Calm drift plus whatever speed the scroll or a throw added, easing back to calm.
const target = s.dir * 60 + s.dir * boost * 8;
s.v += (target - s.v) * 0.06;
s.x += s.v * dt;
}
if (half > 0) {
s.x = ((s.x % half) - half) % half;
}
const speed = Math.max(-1, Math.min(1, s.v / 1800));
t.style.transform = `translate3d(${s.x}px,0,0) skewX(${-speed * 14}deg) scaleY(${1 - Math.abs(speed) * 0.08})`;
t.style.setProperty(
"--spin",
`${(now / 1000) * (90 + Math.abs(s.v) * 0.6)}deg`,
);
t.style.setProperty("--blur", `${Math.abs(speed) * 1.6}px`);
});
raf = requestAnimationFrame(loop);
};
raf = requestAnimationFrame(loop);
return () => {
cancelAnimationFrame(raf);
window.removeEventListener("scroll", onScroll);
el.removeEventListener("wheel", onWheel);
downs.forEach((off) => off());
};
}, [rows]);
return (
<div className="gu-vmq" data-theme={theme} ref={root}>
<p className="gu-vmq__sr">{rows.map((r) => r.join(", ")).join(". ")}</p>
{rows.map((words, i) => (
<div
key={i}
className="gu-vmq__row"
data-row={i % 3}
aria-hidden="true"
>
<div className="gu-vmq__track">
{[0, 1].map((copy) => (
<div key={copy} className="gu-vmq__set">
{[...words, ...words].map((w, j) => (
<span
key={j}
className="gu-vmq__item"
style={{ "--j": j } as CSSProperties}
>
<span className="gu-vmq__word">{w}</span>
<svg className="gu-vmq__star" viewBox="0 0 24 24">
<path d="M12 1.5c.8 5.6 4.9 9.7 10.5 10.5-5.6.8-9.7 4.9-10.5 10.5-.8-5.6-4.9-9.7-10.5-10.5C7.1 11.2 11.2 7.1 12 1.5Z" />
</svg>
</span>
))}
</div>
))}
</div>
</div>
))}
<p className="gu-vmq__hint" aria-hidden="true">
Scroll, or grab a row and throw it
</p>
</div>
);
}
```
### velocity-marquee.css
```css
.gu-vmq {
--fg: #f3eee3;
--bg: #0e0e10;
position: relative;
width: 100%;
padding: 36px 0 28px;
overflow: hidden;
background: var(--bg);
color: var(--fg);
font-family: ui-sans-serif, system-ui, sans-serif;
border-radius: 28px;
}
.gu-vmq[data-theme="light"] {
--fg: #0e0e10;
--bg: #f3eee3;
}
.gu-vmq__row {
overflow: hidden;
padding: 6px 0;
}
.gu-vmq__row[data-row="1"] {
background: #ff5a1f;
color: #0e0e10;
rotate: -2deg;
margin: 10px -2%;
}
.gu-vmq__row[data-row="2"] .gu-vmq__word {
color: transparent;
-webkit-text-stroke: 1.5px var(--fg);
}
.gu-vmq__track {
--spin: 0deg;
--blur: 0px;
display: flex;
width: max-content;
cursor: grab;
touch-action: pan-y;
user-select: none;
will-change: transform;
filter: blur(var(--blur));
transform-origin: 50% 50%;
}
.gu-vmq__track[data-held="true"] {
cursor: grabbing;
}
.gu-vmq__set {
display: flex;
}
.gu-vmq__item {
display: flex;
align-items: center;
gap: 0.35em;
padding-right: 0.35em;
}
.gu-vmq__word {
font-size: clamp(44px, 8vw, 104px);
font-weight: 900;
line-height: 1;
letter-spacing: -0.045em;
white-space: nowrap;
}
.gu-vmq__star {
width: clamp(26px, 4vw, 52px);
height: clamp(26px, 4vw, 52px);
fill: currentColor;
rotate: var(--spin);
}
.gu-vmq__row[data-row="0"] .gu-vmq__star {
fill: #ff5a1f;
}
.gu-vmq__hint {
margin: 18px 24px 0;
font-size: 13px;
font-weight: 600;
opacity: 0.55;
}
.gu-vmq__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
@media (prefers-reduced-motion: reduce) {
.gu-vmq__track {
cursor: default;
flex-wrap: wrap;
width: auto;
}
.gu-vmq__set + .gu-vmq__set {
display: none;
}
}
```
You might also want
Next piece: Sound designer portfolioInfinite marquee
Animations, beginner
Marker highlight
Animations, beginner
Odometer counter
Animations, beginner