Loading…
← All components

Sections · Scroll

Scattered Review Cloud

Holographic foil review cards scattered in every direction, at every depth and angle, overlapping one another. The stage pins while you scroll and the quotes fly in one after the other until the whole cloud is there; hover one and it comes forward.

<ScatteredReviewCloud />Live

Customize

Foil
Accent#f0abfc
Foil#16131f
Text#f6f3fb

Installation

Use it in your project

Or skip the copy-paste

One command: writes the file and installs the dependencies.

$ npx deepui-cli add scattered-review-cloud
01

Install

The 3D packages this component is built on.

Nothing to install: React is all it needs.

02

Add the component

One self-contained file: create components/ScatteredReviewCloud.tsx and paste it in.

components/ScatteredReviewCloud.tsx
1"use client";
2
3import { useEffect, useMemo, useRef, useState } from "react";
4
5// Shared by the testimonial sections: the testimonial shape, the common props and sample content.
6
7interface TestimonialItem {
8 id: string;
9 author: string;
10 role: string;
11 company: string;
12 quote: string;
13 /** 0 to 5 stars. */
14 rating?: number;
15 /** A result worth highlighting, e.g. "+140% conversion". */
16 highlightMetric?: string;
17}
18
19interface DeepTestimonialProps {
20 /** The testimonials, in order. */
21 items: TestimonialItem[];
22 /** Pointer, drag, swipe and tilt. Default true. */
23 interactive?: boolean;
24 /**
25 * Each section has its own material (holographic foil, porcelain, acoustic felt, obsidian): "glass" is its
26 * translucent version, "solid" its opaque one. The default depends on the section.
27 */
28 variant?: "glass" | "solid";
29 /** Speed of the motion (rotation, scrolling, idle float). Default 1. */
30 speed?: number;
31 /** Color of the highlights, of the active card's border and of the card details. Default "#a78bfa". */
32 accentColor?: string;
33 /** Base color of the cards' material (foil, porcelain, felt, stone). The default depends on the section. */
34 surfaceColor?: string;
35 /** Color of the quotes and names. The default depends on the section (dark ink on porcelain, light elsewhere). */
36 textColor?: string;
37 /** Extra classes for the section. */
38 className?: string;
39}
40
41const TESTIMONIAL_DEFAULTS = {
42 interactive: true,
43 variant: "glass",
44 speed: 1,
45 accentColor: "#a78bfa",
46} as const;
47
48// Small pieces of the testimonial cards, shared by every section (no 3D dependency).
49
50/** Five stars, `rating` of them filled. */
51function Stars({ rating, color, size = 13, empty = "rgba(255,255,255,0.18)" }: { rating: number; color: string; size?: number; empty?: string }) {
52 const full = Math.max(0, Math.min(5, Math.round(rating)));
53 return (
54 <span className="flex gap-0.5" role="img" aria-label={`${full} out of 5 stars`}>
55 {Array.from({ length: 5 }, (_, i) => (
56 <svg key={i} viewBox="0 0 20 20" width={size} height={size} aria-hidden="true" style={{ fill: i < full ? color : empty }}>
57 <path d="M10 1.5l2.6 5.4 5.9.8-4.3 4.1 1 5.8L10 14.8l-5.2 2.8 1-5.8L1.5 7.7l5.9-.8z" />
58 </svg>
59 ))}
60 </span>
61 );
62}
63
64/** "AB" from "Ada Byron". */
65function initials(name: string) {
66 return name
67 .split(/\s+/)
68 .filter(Boolean)
69 .slice(0, 2)
70 .map((part) => part[0]?.toUpperCase() ?? "")
71 .join("");
72}
73
74/** `color` at `percent`% opacity, for any CSS color. */
75function fade(color: string, percent: number) {
76 return `color-mix(in srgb, ${color} ${percent}%, transparent)`;
77}
78
79/** The testimonials repeated until there are at least `min` of them (rings, ribbons and clouds need enough cards). */
80function repeatItems(items: TestimonialItem[], min: number) {
81 if (!items.length) return [];
82 // Whole copies of the list, so the same quote never sits next to itself
83 const count = items.length * Math.max(1, Math.ceil(min / items.length));
84 return Array.from({ length: count }, (_, i) => ({ item: items[i % items.length], key: `${items[i % items.length].id}-${i}`, copy: i >= items.length }));
85}
86
87export interface ScatteredReviewCloudProps extends DeepTestimonialProps {
88 /** "solid" (default): opaque holographic foil cards. "glass": translucent foil, the cards behind show through. */
89 variant?: DeepTestimonialProps["variant"];
90 /** Base color of the foil cards. Default "#16131f". */
91 surfaceColor?: string;
92 /** Color of the quotes and names. Default "#f6f3fb". */
93 textColor?: string;
94 /** How many cards make the cloud (the testimonials repeat as needed). Default 18, 11 on phones. */
95 cardCount?: number;
96}
97
98const BACKGROUND = "#07060b";
99const WIDTHS = [264, 300, 336];
100/** Share of the scroll over which the cards appear; the rest lets the full cloud be read. */
101const REVEAL_SPAN = 0.78;
102
103/* -------------------------------------------------------------------------- */
104/* Layout */
105/* -------------------------------------------------------------------------- */
106
107/** Small seeded generator: the same cloud on the server, on every reload and on every screen. */
108function seeded(seed: number) {
109 let a = seed >>> 0;
110 return () => {
111 a = (a + 0x6d2b79f5) >>> 0;
112 let t = a;
113 t = Math.imul(t ^ (t >>> 15), t | 1);
114 t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
115 return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
116 };
117}
118
119interface Spot {
120 /** -1 to 1 across the stage. */
121 x: number;
122 y: number;
123 /** Depth, CSS px (negative = farther). */
124 z: number;
125 rx: number;
126 ry: number;
127 rz: number;
128 scale: number;
129 width: number;
130 /** Scroll progress at which it appears. */
131 reveal: number;
132 phase: number;
133 /** Where it flies in from, relative to its place (px, degrees). */
134 from: { x: number; y: number; z: number; rx: number; ry: number; rz: number };
135}
136
137/**
138 * Loosely spread over the stage (a jittered grid, so no corner stays empty) with no alignment left: every
139 * card has its own depth, size and tilt on all three axes, and neighbours overlap.
140 */
141function scatter(count: number): Spot[] {
142 const rand = seeded(1307 + count);
143 const cols = Math.max(2, Math.round(Math.sqrt(count * 1.7)));
144 const rows = Math.ceil(count / cols);
145 // Shuffled reveal order: the cloud fills in everywhere at once, not row by row
146 const order = Array.from({ length: count }, (_, i) => i);
147 for (let i = count - 1; i > 0; i--) {
148 const j = Math.floor(rand() * (i + 1));
149 [order[i], order[j]] = [order[j], order[i]];
150 }
151 const clamp = (v: number) => Math.max(-1, Math.min(1, v));
152 return Array.from({ length: count }, (_, i) => {
153 const row = Math.floor(i / cols);
154 const inRow = row === rows - 1 ? count - row * cols : cols;
155 const col = i - row * cols;
156 const x = clamp(((col + 0.5) / inRow) * 2 - 1 + (rand() - 0.5) * (2.3 / inRow));
157 const y = clamp(((row + 0.5) / rows) * 2 - 1 + (rand() - 0.5) * (2.3 / rows));
158 return {
159 x,
160 y,
161 z: -460 + rand() * 580,
162 rx: (rand() - 0.5) * 44,
163 ry: (rand() - 0.5) * 62,
164 rz: (rand() - 0.5) * 36,
165 scale: 0.86 + rand() * 0.26,
166 width: WIDTHS[Math.floor(rand() * WIDTHS.length)],
167 reveal: (order.indexOf(i) / Math.max(count - 1, 1)) * REVEAL_SPAN,
168 phase: rand() * Math.PI * 2,
169 from: {
170 x: x * (140 + rand() * 160),
171 y: 160 + rand() * 160,
172 z: -900 - rand() * 500,
173 rx: 50 + rand() * 60,
174 ry: (rand() - 0.5) * 160,
175 rz: (rand() - 0.5) * 120,
176 },
177 };
178 });
179}
180
181/* -------------------------------------------------------------------------- */
182/* Environment */
183/* -------------------------------------------------------------------------- */
184
185function useMedia(query: string) {
186 const [match, setMatch] = useState(false);
187 useEffect(() => {
188 const list = window.matchMedia(query);
189 const update = () => setMatch(list.matches);
190 update();
191 list.addEventListener("change", update);
192 return () => list.removeEventListener("change", update);
193 }, [query]);
194 return match;
195}
196
197/** The element that scrolls the section: a scrolling ancestor (a preview box, a modal) or null for the page. */
198function scrollParent(element: HTMLElement) {
199 for (let parent = element.parentElement; parent; parent = parent.parentElement) {
200 const overflow = getComputedStyle(parent).overflowY;
201 if ((overflow === "auto" || overflow === "scroll") && parent.scrollHeight > parent.clientHeight) return parent;
202 }
203 return null;
204}
205
206/* -------------------------------------------------------------------------- */
207/* Card */
208/* -------------------------------------------------------------------------- */
209
210interface CardProps {
211 item: TestimonialItem;
212 width: number;
213 accent: string;
214 surface: string;
215 text: string;
216 glass: boolean;
217}
218
219/** A holographic foil card: the rainbow sheen slides across it as it turns (--foil, set every frame). */
220function FoilCard({ item, width, accent, surface, text, glass }: CardProps) {
221 const top = `color-mix(in srgb, ${surface} 84%, #ffffff)`;
222 const alpha = glass ? 66 : 100;
223 const sheen = `linear-gradient(115deg, transparent 22%, ${fade("#ff8ad8", 24)} 37%, ${fade("#8af3ff", 24)} 50%, ${fade("#fff09a", 20)} 63%, transparent 78%) var(--foil, 50%) 50% / 280% 280% no-repeat`;
224 return (
225 <figure
226 className="relative m-0 overflow-hidden rounded-[22px] text-left"
227 style={{
228 width,
229 padding: "18px 20px 20px",
230 color: text,
231 background: `${sheen}, linear-gradient(160deg, ${fade(top, alpha)}, ${fade(surface, alpha)})`,
232 backgroundBlendMode: "screen, normal",
233 border: `1px solid ${fade(text, 12)}`,
234 boxShadow: `inset 0 1px 0 ${fade("#ffffff", 16)}, 0 30px 60px -20px rgba(0,0,0,0.8)`,
235 }}
236 >
237 <figcaption className="flex items-center gap-3">
238 <span aria-hidden="true" className="grid size-9 shrink-0 place-items-center rounded-full text-[11px] font-semibold" style={{ background: `conic-gradient(from 210deg, ${accent}, ${fade(accent, 35)}, ${accent})`, color: surface }}>
239 {initials(item.author)}
240 </span>
241 <span className="flex min-w-0 flex-col leading-tight">
242 <span className="truncate text-[13px] font-semibold">{item.author}</span>
243 <span className="truncate text-[11px]" style={{ color: fade(text, 55) }}>
244 {item.role} · {item.company}
245 </span>
246 </span>
247 {item.rating !== undefined ? (
248 <span className="ml-auto self-start pt-0.5">
249 <Stars rating={item.rating} color={accent} size={10} empty={fade(text, 18)} />
250 </span>
251 ) : null}
252 </figcaption>
253 <blockquote className="m-0 mt-3.5 text-[15px] leading-[1.48]" style={{ color: fade(text, 88) }}>
254 “{item.quote}”
255 </blockquote>
256 {item.highlightMetric ? (
257 <p className="m-0 mt-4 inline-flex rounded-full px-2.5 py-1 font-mono text-[10px] font-semibold uppercase tracking-[0.14em]" style={{ color: accent, background: fade(accent, 12), boxShadow: `inset 0 0 0 1px ${fade(accent, 35)}` }}>
258 {item.highlightMetric}
259 </p>
260 ) : null}
261 </figure>
262 );
263}
264
265/* -------------------------------------------------------------------------- */
266/* Section */
267/* -------------------------------------------------------------------------- */
268
269interface CardState {
270 /** Appearance, 0 to 1 (a spring: it overshoots a little). */
271 a: number;
272 v: number;
273 /** Hover, 0 to 1. */
274 h: number;
275}
276
277/**
278 * Testimonials scattered in every direction: no grid, no alignment, cards at all depths and angles,
279 * overlapping one another. The stage stays pinned while you scroll, and the quotes fly in one after the
280 * other, from everywhere at once, until the whole cloud is there. The cloud turns with the scroll and
281 * the pointer; a hovered card comes forward and straightens up. Holographic foil cards, real HTML.
282 */
283export default function ScatteredReviewCloud({
284 items,
285 interactive = TESTIMONIAL_DEFAULTS.interactive,
286 variant = "solid",
287 speed = TESTIMONIAL_DEFAULTS.speed,
288 accentColor = "#f0abfc",
289 surfaceColor = "#16131f",
290 textColor = "#f6f3fb",
291 cardCount,
292 className = "",
293}: ScatteredReviewCloudProps) {
294 const section = useRef<HTMLElement>(null);
295 const stage = useRef<HTMLDivElement>(null);
296 const cloud = useRef<HTMLUListElement>(null);
297 const hint = useRef<HTMLParagraphElement>(null);
298 const cardEls = useRef<(HTMLLIElement | null)[]>([]);
299 const fogEls = useRef<(HTMLSpanElement | null)[]>([]);
300 const hovered = useRef(-1);
301 const reduced = useMedia("(prefers-reduced-motion: reduce)");
302 const mobile = useMedia("(max-width: 767px)");
303
304 const cards = useMemo(() => {
305 const wanted = Math.max(1, Math.round(cardCount ?? (mobile ? 11 : 18)));
306 return repeatItems(items, wanted).slice(0, Math.max(wanted, items.length));
307 }, [items, cardCount, mobile]);
308 const spots = useMemo(() => scatter(cards.length), [cards.length]);
309
310 // Inside a scrolling box (a preview, a modal), the pinned stage is as tall as that box
311 const [boxHeight, setBoxHeight] = useState<number | null>(null);
312 useEffect(() => {
313 const el = section.current;
314 const root = el ? scrollParent(el) : null;
315 if (!root) return undefined;
316 const observer = new ResizeObserver(() => setBoxHeight(root.clientHeight));
317 observer.observe(root);
318 return () => observer.disconnect();
319 }, []);
320
321 const settings = useRef({ speed, interactive, reduced, mobile });
322 useEffect(() => {
323 settings.current = { speed, interactive, reduced, mobile };
324 });
325
326 useEffect(() => {
327 const sectionEl = section.current;
328 const stageEl = stage.current;
329 const cloudEl = cloud.current;
330 if (!sectionEl || !stageEl || !cloudEl) return undefined;
331 const root = scrollParent(sectionEl);
332 const states: CardState[] = spots.map(() => ({ a: 0, v: 0, h: 0 }));
333 const pointer = { x: 0, y: 0, tx: 0, ty: 0 };
334 let shown = 0;
335 let raf = 0;
336 let last = 0;
337 let time = 0;
338
339 const progress = () => {
340 const rect = sectionEl.getBoundingClientRect();
341 const top = root ? rect.top - root.getBoundingClientRect().top : rect.top;
342 const view = root ? root.clientHeight : window.innerHeight;
343 const room = rect.height - view;
344 // Pinned: progress through the section; too short to pin: progress of its entrance
345 if (room > view * 0.25) return Math.min(1, Math.max(0, -top / room));
346 return Math.min(1, Math.max(0, (view - top) / view));
347 };
348
349 const frame = (now: number) => {
350 raf = requestAnimationFrame(frame);
351 const dt = last ? Math.min((now - last) / 1000, 1 / 30) : 1 / 60;
352 last = now;
353 const { speed: s, interactive: live, reduced: still, mobile: small } = settings.current;
354 time += dt * s;
355 const p = still ? 1 : progress();
356 shown += (p - shown) * (1 - Math.exp(-6 * dt));
357
358 // The whole cloud turns with the scroll and leans towards the pointer; the camera pushes in
359 pointer.x += ((live ? pointer.tx : 0) - pointer.x) * (1 - Math.exp(-4 * dt));
360 pointer.y += ((live ? pointer.ty : 0) - pointer.y) * (1 - Math.exp(-4 * dt));
361 const turnY = still ? 0 : (shown - 0.5) * 16 + pointer.x * 7;
362 const turnX = still ? 0 : -pointer.y * 5;
363 const dolly = still ? 0 : -140 + shown * 240;
364 cloudEl.style.transform = `translateZ(${dolly}px) rotateX(${turnX}deg) rotateY(${turnY}deg)`;
365 if (hint.current) hint.current.style.opacity = String(Math.max(0, 1 - p * 14));
366
367 const w = stageEl.clientWidth;
368 const h = stageEl.clientHeight;
369 const unit = small ? Math.min(0.86, Math.max(0.68, w / 560)) : Math.min(1.12, Math.max(0.7, w / 1320));
370 const k = 70 * Math.max(s, 0.3) ** 2;
371 const damping = 2 * Math.sqrt(k) * 0.55;
372
373 spots.forEach((spot, i) => {
374 const el = cardEls.current[i];
375 if (!el) return;
376 const st = states[i];
377 const target = still || p >= spot.reveal ? 1 : 0;
378 if (still) {
379 st.a = 1;
380 st.v = 0;
381 } else {
382 st.v += (k * (target - st.a) - damping * st.v) * dt;
383 st.a += st.v * dt;
384 }
385 st.h += ((live && hovered.current === i ? 1 : 0) - st.h) * (1 - Math.exp(-8 * dt));
386 const a = st.a;
387 const away = 1 - a;
388 const straight = 1 - st.h * 0.8;
389 const bob = still ? 0 : Math.sin(time * 0.7 + spot.phase) * 7;
390 const sway = still ? 0 : Math.sin(time * 0.45 + spot.phase) * 1.6;
391 const width = spot.width * unit * spot.scale;
392 const x = spot.x * (w / 2 - width * 0.3) + away * spot.from.x;
393 const y = spot.y * (h / 2 - width * 0.25) + away * spot.from.y + bob;
394 const z = spot.z + away * spot.from.z + st.h * 170;
395 const rx = (spot.rx + away * spot.from.rx) * straight;
396 const ry = (spot.ry + away * spot.from.ry) * straight;
397 const rz = (spot.rz + away * spot.from.rz + sway) * straight;
398 el.style.transform = `translate(-50%,-50%) translate3d(${x.toFixed(1)}px,${y.toFixed(1)}px,${z.toFixed(1)}px) rotateX(${rx.toFixed(2)}deg) rotateY(${ry.toFixed(2)}deg) rotateZ(${rz.toFixed(2)}deg) scale(${(unit * spot.scale * (1 + st.h * 0.05)).toFixed(4)})`;
399 el.style.opacity = String(Math.min(1, Math.max(0, a * 1.6)));
400 el.style.visibility = a < 0.004 && target === 0 ? "hidden" : "visible";
401 el.style.pointerEvents = live && a > 0.6 ? "auto" : "none";
402 el.style.setProperty("--foil", `${(50 + (ry + rz + turnY) * 1.3).toFixed(1)}%`);
403 // Far cards sink into the dark
404 const fog = fogEls.current[i];
405 if (fog) fog.style.opacity = String(Math.min(0.6, Math.max(0, -(spot.z + dolly) / 900)) * (1 - st.h));
406 });
407 };
408
409 const start = () => {
410 if (raf) return;
411 last = 0;
412 raf = requestAnimationFrame(frame);
413 };
414 const stop = () => {
415 cancelAnimationFrame(raf);
416 raf = 0;
417 };
418 // Runs only while on screen
419 const observer = new IntersectionObserver(([entry]) => {
420 if (entry.isIntersecting) start();
421 else stop();
422 });
423 observer.observe(sectionEl);
424
425 const onPointer = (event: PointerEvent) => {
426 const r = stageEl.getBoundingClientRect();
427 pointer.tx = Math.max(-1, Math.min(1, ((event.clientX - r.left) / r.width) * 2 - 1));
428 pointer.ty = -Math.max(-1, Math.min(1, ((event.clientY - r.top) / r.height) * 2 - 1));
429 };
430 window.addEventListener("pointermove", onPointer, { passive: true });
431 return () => {
432 observer.disconnect();
433 stop();
434 window.removeEventListener("pointermove", onPointer);
435 };
436 }, [spots]);
437
438 const glass = variant === "glass";
439 return (
440 <section ref={section} aria-label="Customer testimonials" className={`relative h-[300svh] w-full ${className}`} style={{ background: BACKGROUND }}>
441 <div ref={stage} className="sticky top-0 h-svh w-full overflow-hidden" style={{ height: boxHeight ?? undefined, perspective: 1100 }}>
442 <ul ref={cloud} className="absolute inset-0 m-0 list-none p-0" style={{ transformStyle: "preserve-3d" }}>
443 {cards.map((card, i) => (
444 <li
445 key={card.key}
446 ref={(el) => {
447 cardEls.current[i] = el;
448 }}
449 aria-hidden={card.copy ? true : undefined}
450 className="absolute left-1/2 top-1/2"
451 style={{ visibility: "hidden", opacity: 0, willChange: "transform, opacity" }}
452 onPointerEnter={() => {
453 hovered.current = i;
454 }}
455 onPointerLeave={() => {
456 if (hovered.current === i) hovered.current = -1;
457 }}
458 >
459 <FoilCard item={card.item} width={spots[i]?.width ?? WIDTHS[1]} accent={accentColor} surface={surfaceColor} text={textColor} glass={glass} />
460 <span
461 ref={(el) => {
462 fogEls.current[i] = el;
463 }}
464 aria-hidden="true"
465 className="pointer-events-none absolute inset-0 rounded-[22px]"
466 style={{ background: BACKGROUND, opacity: 0 }}
467 />
468 </li>
469 ))}
470 </ul>
471 <p ref={hint} aria-hidden="true" className="pointer-events-none absolute inset-x-0 bottom-8 m-0 text-center font-mono text-[10px] uppercase tracking-[0.32em]" style={{ color: fade(textColor, 45) }}>
472 Scroll
473 </p>
474 </div>
475 </section>
476 );
477}
03

Drop it in a page

Updated live with the settings above.

app/page.tsx
1import ScatteredReviewCloud from "@/components/ScatteredReviewCloud";
2
3export default function Section() {
4 return (
5 // The component fills this box: give it a position and a height
6 <div style={{ position: "relative", width: "100%", height: "100vh" }}>
7 <ScatteredReviewCloud
8 variant="solid"
9 speed={1}
10 cardCount={18}
11 accentColor="#f0abfc"
12 surfaceColor="#16131f"
13 textColor="#f6f3fb"
14 interactive
15 items={testimonials}
16 />
17 </div>
18 );
19}
Next componentPerspective Dual Wall→