← All components Next componentMonolith Stack Deck→
Sections · Marquee
Perspective Dual Wall
Two endless ribbons of glazed porcelain cards, dark ink on white, sliding in opposite directions across a wall tilted in space; a light at the center sweeps their edges and page scroll speeds them up.
<PerspectiveDualWallMarquee />Live
Scroll the page · hover a card
Customize
Porcelain
Accent#c084fc
Porcelain#f2eff6
Text#17151d
Installation
Use it in your project
Or skip the copy-paste
One command: writes the file and installs the dependencies.
$ npx deepui-cli add perspective-dual-wall-marquee
01
Install
The 3D packages this component is built on.
$ npm install three @react-three/fiber @react-three/drei && npm install -D @types/three
02
Add the component
One self-contained file: create components/PerspectiveDualWallMarquee.tsx and paste it in.
components/PerspectiveDualWallMarquee.tsx
1"use client";23import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode, type RefObject } from "react";4import * as THREE from "three";5import { RoundedBoxGeometry } from "three/examples/jsm/geometries/RoundedBoxGeometry.js";6import { Canvas, useFrame, useThree, type CanvasProps } from "@react-three/fiber";7import { Environment, Lightformer } from "@react-three/drei";89/**10 * The shared props API of DeepUI's individual 3D components (not the full-page templates, which keep11 * their own tailored scenes).12 *13 * The props are grouped by concern. A component extends ONLY the groups it really applies, so its14 * type never advertises a knob that does nothing (a card has no particles, a background has no tilt):15 *16 * interface MyCardProps extends CursorProps, TiltProps, MaterialProps, PerformanceProps { … }17 *18 * `Base3DComponentProps` is every group at once, for tooling that handles any component. Same name,19 * same unit and same meaning everywhere; the default values live in DEFAULT_3D_PROPS. These files are20 * inlined into each component's single-file bundle (lib/bundle-source.mjs), only what it uses.21 */2223/** Which rotation axes follow the pointer. "x-only": the object nods (up / down); "y-only": it turns (left / right). */24export type TiltAxis = "both" | "x-only" | "y-only" | "none";2526/** 1. Cursor: how the pointer pulls, pushes and drags the object. */27interface CursorProps {28 /** Reach of the pointer's influence, in the component's own space: CSS pixels for pixel-laid-out widgets, world units for 3D scenes (each component says which). Default 220 (px). */29 cursorRadius?: number;30 /** Positive pulls things towards the pointer, negative pushes them away (repulsion, shockwave). Default 1. */31 cursorForce?: number;32 /** How far the object slides towards the pointer, 0 (stays put) to 1 (follows closely). Default 0. */33 magneticStrength?: number;34 /** Share of the remaining distance the motion closes each frame (at 60 fps), 0.01 (heavy, slow) to 1 (instant). Default 0.1. */35 cursorDamping?: number;36}3738/** 2. Tilt and parallax: the object leans towards the pointer, its layers slide against each other. */39interface TiltProps {40 /** Largest lean towards the pointer, in degrees. Default 15. */41 maxTiltAngle?: number;42 /** Axes that follow the pointer. Default "both". */43 tiltAxis?: TiltAxis;44 /** Lean away from the pointer instead of towards it. Default false. */45 invertTilt?: boolean;46 /** How far apart the depth layers slide when the object tilts, 0 (flat) to 2. Default 1. */47 parallaxOffset?: number;48}4950/** 3. Text and 3D typography, for components that draw a label. */51interface Text3DProps {52 /** The label drawn by the component. */53 text?: string;54 /** Scale of the lettering. Default 1. */55 fontSize?: number;56 /** Extrusion depth of 3D letters. Default 0.2. */57 textDepth?: number;58 /** Bevelled, light-catching edges on 3D letters. Default true. */59 bevelEnabled?: boolean;60 /** Custom font: a .woff / .ttf (flat text) or a typeface .json (extruded text). */61 fontUrl?: string;62}6364/** 4. Rendering, materials and glow. */65interface MaterialProps {66 /** Main color of the object. Default "#6366f1". */67 primaryColor?: string;68 /** Color of the glow. Default "#00f0ff". */69 emissiveColor?: string;70 /** Strength of the glow, 0 (none) to 3. Default 1. */71 emissiveIntensity?: number;72 /** 0 (mirror, glass) to 1 (matte). Default 0.3. */73 roughness?: number;74 /** 0 (plastic, organic) to 1 (metal). Default 0.5. */75 metalness?: number;76 /** 0 (opaque) to 1 (clear glass): see-through, refracting surfaces. Default 0. */77 transmission?: number;78 /** Technical wireframe rendering. Default false. */79 wireframe?: boolean;80}8182/** 5. Particles, idle motion and shader animation. */83interface MotionProps {84 /** Number of instanced elements. Default depends on the component. */85 particleCount?: number;86 /** Spin on its own, in radians per second (negative: the other way; 0.5 ≈ one turn in 12 s). Default 0. */87 autoRotateSpeed?: number;88 /** Pulses or ripples per second. Default 1. */89 pulseRate?: number;90 /** Amplitude of the noise deformation, 0 (none) to 2. Default 1. */91 displacementScale?: number;92}9394/** 6. Environment and camera. */95interface EnvironmentProps {96 /** Camera field of view, in degrees. Default depends on the component. */97 cameraFov?: number;98 /** Color of the depth fog. Default "#0a0a0a". */99 fogColor?: string;100 /** Thickness of the fog, 0 (none) to 0.2. Default 0. */101 fogDensity?: number;102}103104/** 7. Performance and accessibility. */105interface PerformanceProps {106 /** Lighter rendering for weak devices: pixel ratio 1, fewer instances, smaller environment maps. Default false. */107 lowPowerMode?: boolean;108 /** Under the OS "reduce motion" setting, stop idle spin, pulses and deformation (pointer feedback stays). Default true. */109 respectReducedMotion?: boolean;110 /** Stop the render loop while the component is scrolled out of view. Default true. */111 pauseWhenOffscreen?: boolean;112}113114/** Every group at once. Components extend only the groups they apply (see the top of this file). */115interface Base3DComponentProps116 extends CursorProps,117 TiltProps,118 Text3DProps,119 MaterialProps,120 MotionProps,121 EnvironmentProps,122 PerformanceProps {}123124type Defaults = Required<Omit<Base3DComponentProps, "text" | "fontUrl" | "particleCount" | "cameraFov">>;125126/** The values a prop takes when it is left out. A component may override one, and then documents it. */127const DEFAULT_3D_PROPS: Defaults = {128 cursorRadius: 220,129 cursorForce: 1,130 magneticStrength: 0,131 cursorDamping: 0.1,132 maxTiltAngle: 15,133 tiltAxis: "both",134 invertTilt: false,135 parallaxOffset: 1,136 fontSize: 1,137 textDepth: 0.2,138 bevelEnabled: true,139 primaryColor: "#6366f1",140 emissiveColor: "#00f0ff",141 emissiveIntensity: 1,142 roughness: 0.3,143 metalness: 0.5,144 transmission: 0,145 wireframe: false,146 autoRotateSpeed: 0,147 pulseRate: 1,148 displacementScale: 1,149 fogColor: "#0a0a0a",150 fogDensity: 0,151 lowPowerMode: false,152 respectReducedMotion: true,153 pauseWhenOffscreen: true,154};155156/** True under 768px: scenes recompose (camera farther, layouts in columns). */157function useIsMobile() {158 const [mobile, setMobile] = useState(false);159 useEffect(() => {160 const query = window.matchMedia("(max-width: 767px)");161 const sync = () => setMobile(query.matches);162 sync();163 query.addEventListener("change", sync);164 return () => query.removeEventListener("change", sync);165 }, []);166 return mobile;167}168169function usePrefersReducedMotion() {170 const [reduced, setReduced] = useState(false);171 useEffect(() => {172 const query = window.matchMedia("(prefers-reduced-motion: reduce)");173 const sync = () => setReduced(query.matches);174 sync();175 query.addEventListener("change", sync);176 return () => query.removeEventListener("change", sync);177 }, []);178 return reduced;179}180181/**182 * The <Canvas> frameloop for `pauseWhenOffscreen`: "never" while the element is out of view. Put the ref183 * on the element that wraps the canvas (outside it: this hook runs in the component, not in the scene).184 */185function useOffscreenFrameloop(ref: RefObject<HTMLElement | null>, pauseWhenOffscreen: boolean = DEFAULT_3D_PROPS.pauseWhenOffscreen): "always" | "never" {186 // In view at first: some WebGL backends show an opaque canvas if it is paused before its first frame187 const [inView, setInView] = useState(true);188 useEffect(() => {189 const el = ref.current;190 if (!el || !pauseWhenOffscreen) return undefined;191 const observer = new IntersectionObserver(([entry]) => setInView(entry.isIntersecting));192 observer.observe(el);193 return () => observer.disconnect();194 }, [ref, pauseWhenOffscreen]);195 return !pauseWhenOffscreen || inView ? "always" : "never";196}197198// Shared by the testimonial sections: the testimonial shape, the common props and sample content.199200interface TestimonialItem {201 id: string;202 author: string;203 role: string;204 company: string;205 quote: string;206 /** 0 to 5 stars. */207 rating?: number;208 /** A result worth highlighting, e.g. "+140% conversion". */209 highlightMetric?: string;210}211212interface DeepTestimonialProps {213 /** The testimonials, in order. */214 items: TestimonialItem[];215 /** Pointer, drag, swipe and tilt. Default true. */216 interactive?: boolean;217 /**218 * Each section has its own material (holographic foil, porcelain, acoustic felt, obsidian): "glass" is its219 * translucent version, "solid" its opaque one. The default depends on the section.220 */221 variant?: "glass" | "solid";222 /** Speed of the motion (rotation, scrolling, idle float). Default 1. */223 speed?: number;224 /** Color of the highlights, of the active card's border and of the card details. Default "#a78bfa". */225 accentColor?: string;226 /** Base color of the cards' material (foil, porcelain, felt, stone). The default depends on the section. */227 surfaceColor?: string;228 /** Color of the quotes and names. The default depends on the section (dark ink on porcelain, light elsewhere). */229 textColor?: string;230 /** Extra classes for the section. */231 className?: string;232}233234const TESTIMONIAL_DEFAULTS = {235 interactive: true,236 variant: "glass",237 speed: 1,238 accentColor: "#a78bfa",239} as const;240241// Small pieces of the testimonial cards, shared by every section (no 3D dependency).242243/** Five stars, `rating` of them filled. */244function Stars({ rating, color, size = 13, empty = "rgba(255,255,255,0.18)" }: { rating: number; color: string; size?: number; empty?: string }) {245 const full = Math.max(0, Math.min(5, Math.round(rating)));246 return (247 <span className="flex gap-0.5" role="img" aria-label={`${full} out of 5 stars`}>248 {Array.from({ length: 5 }, (_, i) => (249 <svg key={i} viewBox="0 0 20 20" width={size} height={size} aria-hidden="true" style={{ fill: i < full ? color : empty }}>250 <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" />251 </svg>252 ))}253 </span>254 );255}256257/** "AB" from "Ada Byron". */258function initials(name: string) {259 return name260 .split(/\s+/)261 .filter(Boolean)262 .slice(0, 2)263 .map((part) => part[0]?.toUpperCase() ?? "")264 .join("");265}266267/** `color` at `percent`% opacity, for any CSS color. */268function fade(color: string, percent: number) {269 return `color-mix(in srgb, ${color} ${percent}%, transparent)`;270}271272// Building blocks of the testimonial sections. The quotes are real HTML of the section, laid in 3D over273// the canvas (see the card layer below): crisp on any screen, selectable, read by screen readers and274// indexed, and present even before WebGL has started.275276/** CSS size of a card's HTML. Its 3D slab has the same proportions. */277const CARD_PX = { width: 360, height: 236 };278279const CARD_ASPECT = CARD_PX.height / CARD_PX.width;280281type Variant = NonNullable<DeepTestimonialProps["variant"]>;282283function isTouchDevice() {284 return typeof window !== "undefined" && window.matchMedia("(pointer: coarse)").matches;285}286287interface TestimonialCanvasProps extends Omit<CanvasProps, "children" | "style" | "gl" | "frameloop" | "dpr"> {288 children: ReactNode;289}290291/**292 * Canvas filling its positioned parent: pixel ratio capped (1.5 on touch screens), render loop paused293 * off-screen. The canvas itself ignores the pointer; the cards (HTML) and the section handle it.294 */295function TestimonialCanvas({ children, ...canvasProps }: TestimonialCanvasProps) {296 const ref = useRef<HTMLDivElement>(null);297 const frameloop = useOffscreenFrameloop(ref, true);298 const [touch] = useState(isTouchDevice);299 return (300 <div ref={ref} className="absolute inset-0">301 <Canvas302 dpr={[1, touch ? 1.5 : 2]}303 frameloop={frameloop}304 gl={{ antialias: !touch, alpha: true, powerPreference: "high-performance" }}305 style={{ pointerEvents: "none" }}306 {...canvasProps}307 >308 {children}309 </Canvas>310 </div>311 );312}313314/** Procedural studio lighting (no HDR file): soft key, two strip lights, one in the accent color. */315function StudioLights({ accent }: { accent: string }) {316 return (317 <>318 <ambientLight intensity={0.35} />319 <directionalLight position={[3, 5, 6]} intensity={1.4} />320 <Environment resolution={256} frames={1}>321 <Lightformer form="rect" intensity={2.2} position={[0, 6, 4]} rotation-x={-Math.PI / 3} scale={[12, 3, 1]} />322 <Lightformer form="rect" intensity={3} color={accent} position={[-7, 1, 2]} rotation-y={Math.PI / 2} scale={[10, 1.2, 1]} />323 <Lightformer form="rect" intensity={1.6} position={[7, -1, 3]} rotation-y={-Math.PI / 2} scale={[10, 1, 1]} />324 <Lightformer form="ring" intensity={1.2} color={accent} position={[0, 0, -6]} scale={4} />325 </Environment>326 </>327 );328}329330/** Bends a geometry around the Y axis (radius > 0, convex side towards +Z). */331function bend(geometry: THREE.BufferGeometry, radius: number) {332 const pos = geometry.attributes.position as THREE.BufferAttribute;333 for (let i = 0; i < pos.count; i++) {334 const x = pos.getX(i);335 const z = pos.getZ(i);336 const a = x / radius;337 const r = radius + z;338 pos.setXYZ(i, Math.sin(a) * r, pos.getY(i), Math.cos(a) * r - radius);339 }340 geometry.computeVertexNormals();341 return geometry;342}343344function roundedRect(width: number, height: number, radius: number) {345 const shape = new THREE.Shape();346 const w = width / 2;347 const h = height / 2;348 const r = Math.min(radius, w, h);349 shape.moveTo(-w + r, -h);350 shape.lineTo(w - r, -h);351 shape.quadraticCurveTo(w, -h, w, -h + r);352 shape.lineTo(w, h - r);353 shape.quadraticCurveTo(w, h, w - r, h);354 shape.lineTo(-w + r, h);355 shape.quadraticCurveTo(-w, h, -w, h - r);356 shape.lineTo(-w, -h + r);357 shape.quadraticCurveTo(-w, -h, -w + r, -h);358 return shape;359}360361/** Imperative handle of a slab: fade and highlight it from useFrame, without re-rendering. */362interface SlabHandle {363 group: THREE.Group | null;364 /** 0 (invisible) to 1. */365 setOpacity: (opacity: number) => void;366 /** 0 to 1: glow of the accent border. */367 setHighlight: (amount: number) => void;368}369370/**371 * The material family of a slab. Each section has its own:372 * - "porcelain": frosted white acrylic (glass) or glazed porcelain (solid), for dark ink text.373 * - "felt": perforated acoustic felt, behind a thin glass sheet (glass) or bare (solid).374 */375type Finish = "porcelain" | "felt";376377/** Fibers and a grid of perforations, as a bump map (1 world unit per repeat). */378function feltTexture() {379 const size = 256;380 const canvas = document.createElement("canvas");381 canvas.width = canvas.height = size;382 const ctx = canvas.getContext("2d");383 if (ctx) {384 ctx.fillStyle = "#808080";385 ctx.fillRect(0, 0, size, size);386 // Short random fibers387 for (let i = 0; i < 2600; i++) {388 const x = Math.random() * size;389 const y = Math.random() * size;390 const a = Math.random() * Math.PI;391 const l = 2 + Math.random() * 6;392 const shade = 100 + Math.random() * 70;393 ctx.strokeStyle = `rgba(${shade},${shade},${shade},0.55)`;394 ctx.lineWidth = 0.6;395 ctx.beginPath();396 ctx.moveTo(x, y);397 ctx.lineTo(x + Math.cos(a) * l, y + Math.sin(a) * l);398 ctx.stroke();399 }400 // Perforations: 8 per world unit401 const step = size / 8;402 for (let gx = 0; gx < 8; gx++) {403 for (let gy = 0; gy < 8; gy++) {404 const g = ctx.createRadialGradient(gx * step + step / 2, gy * step + step / 2, 0, gx * step + step / 2, gy * step + step / 2, step * 0.2);405 g.addColorStop(0, "#000000");406 g.addColorStop(0.75, "#202020");407 g.addColorStop(1, "rgba(128,128,128,0)");408 ctx.fillStyle = g;409 ctx.beginPath();410 ctx.arc(gx * step + step / 2, gy * step + step / 2, step * 0.2, 0, Math.PI * 2);411 ctx.fill();412 }413 }414 }415 const texture = new THREE.CanvasTexture(canvas);416 texture.wrapS = texture.wrapT = THREE.RepeatWrapping;417 texture.colorSpace = THREE.NoColorSpace;418 return texture;419}420421interface SlabMaterials {422 body: THREE.MeshPhysicalMaterial;423 face: THREE.MeshPhysicalMaterial;424 faceOpacity: number;425 textures: THREE.Texture[];426}427428function slabMaterials(finish: Finish, variant: Variant, surface: string): SlabMaterials {429 const glass = variant === "glass";430 const tint = new THREE.Color(surface);431432 if (finish === "porcelain") {433 const body = glass434 ? new THREE.MeshPhysicalMaterial({ color: tint, transmission: 0.85, thickness: 0.6, roughness: 0.5, ior: 1.45, clearcoat: 0.4, transparent: true })435 : new THREE.MeshPhysicalMaterial({ color: tint, roughness: 0.3, clearcoat: 0.9, clearcoatRoughness: 0.18, transparent: true });436 const face = new THREE.MeshPhysicalMaterial({ color: tint, roughness: glass ? 0.62 : 0.48, clearcoat: glass ? 0 : 0.5, clearcoatRoughness: 0.3, transparent: true, opacity: glass ? 0.82 : 1 });437 return { body, face, faceOpacity: glass ? 0.82 : 1, textures: [] };438 }439440 const bump = feltTexture();441 const sheen = tint.clone().lerp(new THREE.Color("#ffffff"), 0.35);442 const felt = () => new THREE.MeshPhysicalMaterial({ color: tint, roughness: 1, metalness: 0, sheen: 1, sheenRoughness: 0.65, sheenColor: sheen, bumpMap: bump, bumpScale: 1.4, transparent: true });443 const body = felt();444 // Glass: a thin clear sheet over the felt; solid: the felt itself, perforations and all445 const face = glass446 ? new THREE.MeshPhysicalMaterial({ color: "#ffffff", transmission: 1, thickness: 0.08, roughness: 0.04, ior: 1.5, clearcoat: 1, clearcoatRoughness: 0.03, transparent: true })447 : felt();448 return { body, face, faceOpacity: 1, textures: [bump] };449}450451interface SlabProps {452 width: number;453 /** Width / height ratio of the HTML card it carries. Default CARD_ASPECT. */454 aspect?: number;455 finish: Finish;456 variant: Variant;457 /** Base color of the material (porcelain, felt). */458 surface: string;459 accent: string;460 /** Thickness, world units. Default 0.14. */461 depth?: number;462 /** Bend radius (a slab cut from a cylinder). 0 = flat. */463 curve?: number;464 handle: (api: SlabHandle) => void;465 children?: ReactNode;466}467468/** A card's 3D body, in one of the material families above. An accent border glows when highlighted. */469function Slab({ width, aspect = CARD_ASPECT, finish, variant, surface, accent, depth = 0.14, curve = 0, handle, children }: SlabProps) {470 const height = width * aspect;471 const radius = Math.min(width, height) * 0.08;472473 const geometries = useMemo(() => {474 const body = curve > 0 ? bend(new THREE.BoxGeometry(width, height, depth, 32, 1, 1), curve) : new RoundedBoxGeometry(width, height, depth, 4, radius);475 if (curve > 0) {476 // Enough columns to follow the bend477 const flat = new THREE.PlaneGeometry(width - depth * 0.9, height - depth * 0.9, 32, 1);478 flat.translate(0, 0, depth / 2 + 0.004);479 bend(flat, curve);480 return { body, face: flat, rim: bend(new THREE.BoxGeometry(width * 1.03, height * 1.05, depth * 0.6, 32, 1, 1), curve) };481 }482 const face = new THREE.ShapeGeometry(roundedRect(width - depth * 0.9, height - depth * 0.9, radius * 0.8), 12);483 face.translate(0, 0, depth / 2 + 0.004);484 const rim = new THREE.ShapeGeometry(roundedRect(width * 1.035, height * 1.05, radius * 1.1), 12);485 rim.translate(0, 0, -depth / 2 - 0.004);486 return { body, face, rim };487 }, [width, height, depth, radius, curve]);488489 const materials = useMemo(() => {490 const set = slabMaterials(finish, variant, surface);491 const rim = new THREE.MeshBasicMaterial({ color: accent, transparent: true, opacity: 0, toneMapped: false, depthWrite: false });492 return { ...set, rim };493 }, [finish, variant, surface, accent]);494495 useEffect(() => () => Object.values(geometries).forEach((g) => g.dispose()), [geometries]);496 useEffect(497 () => () => {498 materials.body.dispose();499 materials.face.dispose();500 materials.rim.dispose();501 materials.textures.forEach((t) => t.dispose());502 },503 [materials]504 );505506 const group = useRef<THREE.Group>(null);507 const opacity = useRef(1);508 const highlight = useRef(0);509 useEffect(() => {510 const apply = () => {511 const o = opacity.current;512 materials.body.opacity = o;513 materials.face.opacity = materials.faceOpacity * o;514 materials.rim.opacity = highlight.current * 0.85 * o;515 if (group.current) group.current.visible = o > 0.01;516 };517 handle({518 get group() {519 return group.current;520 },521 setOpacity(value) {522 if (Math.abs(value - opacity.current) < 0.002) return;523 opacity.current = value;524 apply();525 },526 setHighlight(value) {527 if (Math.abs(value - highlight.current) < 0.002) return;528 highlight.current = value;529 apply();530 },531 });532 apply();533 }, [handle, materials]);534535 return (536 <group ref={group}>537 <mesh geometry={geometries.rim} material={materials.rim} renderOrder={0} />538 <mesh geometry={geometries.body} material={materials.body} renderOrder={1} />539 <mesh geometry={geometries.face} material={materials.face} renderOrder={2} />540 {children}541 </group>542 );543}544545/** The card layouts, one per material family. */546type CardTheme = "porcelain" | "felt";547548/** Default text color of each layout. */549const CARD_TEXT: Record<CardTheme, string> = { porcelain: "#17151d", felt: "#efeaf6" };550551interface TestimonialCardProps {552 item: TestimonialItem;553 accent: string;554 theme: CardTheme;555 /** Text color. Default: CARD_TEXT[theme]. */556 text?: string;557}558559const figureStyle = { width: CARD_PX.width, height: CARD_PX.height, backfaceVisibility: "hidden", WebkitBackfaceVisibility: "hidden" } as const;560561/** The quote as semantic HTML: a figure with a blockquote and its attribution. */562function TestimonialCard({ item, accent, theme, text = CARD_TEXT[theme] }: TestimonialCardProps) {563 if (theme === "porcelain") {564 // Editorial: dark ink on white, a large accent quote mark, an initials badge565 return (566 <figure className="relative m-0 flex flex-col overflow-hidden text-left" style={{ ...figureStyle, color: text, padding: "18px 24px 20px" }}>567 <div className="flex items-start justify-between">568 <span aria-hidden="true" className="font-serif text-[52px] leading-[0.8]" style={{ color: accent }}>569 “570 </span>571 {item.highlightMetric ? (572 <span className="mt-1 rounded-md px-2 py-1 font-mono text-[10px] font-semibold uppercase tracking-[0.1em]" style={{ background: fade(text, 6), color: fade(text, 70) }}>573 {item.highlightMetric}574 </span>575 ) : null}576 </div>577 <blockquote className="m-0 mt-1 line-clamp-4 font-serif text-[16px] leading-[1.42]" style={{ color: fade(text, 90) }}>578 {item.quote}579 </blockquote>580 <figcaption className="mt-auto flex items-center gap-3">581 <span aria-hidden="true" className="grid size-8 shrink-0 place-items-center rounded-full text-[11px] font-semibold text-white" style={{ background: `linear-gradient(135deg, ${accent}, ${text})` }}>582 {initials(item.author)}583 </span>584 <span className="flex min-w-0 flex-col">585 <span className="text-[13px] font-semibold">{item.author}</span>586 <span className="truncate text-[11px]" style={{ color: fade(text, 55) }}>587 {item.role} · {item.company}588 </span>589 </span>590 {item.rating !== undefined ? (591 <span className="ml-auto">592 <Stars rating={item.rating} color={text} size={11} empty={fade(text, 15)} />593 </span>594 ) : null}595 </figcaption>596 </figure>597 );598 }599600 // Felt: quiet and centered, the metric as an eyebrow, the quote, the name601 return (602 <figure className="m-0 flex flex-col items-center justify-center overflow-hidden text-center" style={{ ...figureStyle, color: text, padding: "20px 26px" }}>603 {item.highlightMetric ? (604 <span className="font-mono text-[10px] uppercase tracking-[0.28em]" style={{ color: accent }}>605 {item.highlightMetric}606 </span>607 ) : null}608 <blockquote className="m-0 mt-3 line-clamp-4 text-[15px] font-light leading-[1.5]" style={{ color: fade(text, 90) }}>609 “{item.quote}”610 </blockquote>611 <figcaption className="mt-4 flex flex-col items-center gap-1">612 <span className="text-[12px] font-medium tracking-[0.04em]">613 {item.author} <span style={{ color: fade(text, 45) }}>— {item.company}</span>614 </span>615 {item.rating !== undefined ? <Stars rating={item.rating} color={accent} size={10} empty={fade(text, 18)} /> : null}616 </figcaption>617 </figure>618 );619}620621// The cards are ordinary DOM elements of the section (same React tree, server-friendly, no portal), laid622// in 3D with CSS: a "camera" element reproduces the WebGL camera (perspective + inverse view matrix)623// and each card takes the world matrix of an anchor object in the scene, like three's CSS3DRenderer.624// The anchors are scaled so a card spans its slab.625626interface CardLayer {627 view: RefObject<HTMLDivElement | null>;628 camera: RefObject<HTMLDivElement | null>;629 anchors: RefObject<(THREE.Object3D | null)[]>;630 elements: RefObject<(HTMLDivElement | null)[]>;631}632633function useCardLayer(): CardLayer {634 const view = useRef<HTMLDivElement>(null);635 const camera = useRef<HTMLDivElement>(null);636 const anchors = useRef<(THREE.Object3D | null)[]>([]);637 const elements = useRef<(HTMLDivElement | null)[]>([]);638 return useMemo(() => ({ view, camera, anchors, elements }), []);639}640641/** Where card `index` lies in the scene: put it inside the card's group, just in front of its slab. */642function CardAnchor({ layer, index, width, z, px = CARD_PX.width }: { layer: CardLayer; index: number; width: number; z: number; px?: number }) {643 return (644 <group645 ref={(object) => {646 layer.anchors.current[index] = object;647 }}648 position={[0, 0, z]}649 scale={width / px}650 />651 );652}653654const cssNumber = (v: number) => (Math.abs(v) < 1e-10 ? 0 : v);655656// The layer measures the world in CSS pixels (WORLD_PX per world unit) so the cards keep a transform scale657// close to 1: at a tiny scale (1 px per unit), Chromium rasterizes the text far from its layout box.658// Scaling the whole view space does not change the perspective projection.659const WORLD_PX = 150;660661function cameraCss(m: THREE.Matrix4) {662 const e = m.elements;663 const k = WORLD_PX;664 const f = [e[0], -e[1], e[2], e[3], e[4], -e[5], e[6], e[7], e[8], -e[9], e[10], e[11], e[12] * k, -e[13] * k, e[14] * k, e[15]];665 return `matrix3d(${f.map(cssNumber).join(",")})`;666}667668function objectCss(m: THREE.Matrix4) {669 const e = m.elements;670 const k = WORLD_PX;671 const f = [e[0] * k, e[1] * k, e[2] * k, e[3], -e[4] * k, -e[5] * k, -e[6] * k, -e[7], e[8] * k, e[9] * k, e[10] * k, e[11], e[12] * k, e[13] * k, e[14] * k, e[15]];672 return `translate(-50%,-50%)matrix3d(${f.map(cssNumber).join(",")})`;673}674675/** Inside the Canvas, after the scene: copies the camera and the anchors onto the card layer every frame. */676function CardLayerSync({ layer }: { layer: CardLayer }) {677 const last = useRef({ perspective: -1, width: -1, height: -1 });678 useFrame(({ camera, size }) => {679 const view = layer.view.current;680 const cam = layer.camera.current;681 if (!view || !cam) return;682 const perspective = (camera as THREE.PerspectiveCamera).projectionMatrix.elements[5] * 0.5 * size.height;683 const l = last.current;684 if (l.perspective !== perspective) {685 view.style.perspective = `${perspective}px`;686 view.style.visibility = "visible";687 l.perspective = perspective;688 }689 if (l.width !== size.width || l.height !== size.height) {690 cam.style.width = `${size.width}px`;691 cam.style.height = `${size.height}px`;692 l.width = size.width;693 l.height = size.height;694 }695 camera.updateMatrixWorld();696 cam.style.transform = `translateZ(${perspective}px)${cameraCss(camera.matrixWorldInverse)}translate(${size.width / 2}px,${size.height / 2}px)`;697 layer.anchors.current.forEach((anchor, i) => {698 const el = layer.elements.current[i];699 if (!anchor || !el) return;700 anchor.updateWorldMatrix(true, false);701 el.style.transform = objectCss(anchor.matrixWorld);702 });703 });704 return null;705}706707/** The DOM side of the layer, over the canvas. Its cards are LayerCards. */708function CardLayerView({ layer, children }: { layer: CardLayer; children: ReactNode }) {709 return (710 // Hidden until the first frame has placed the cards (before that they would pile up in a corner)711 <div ref={layer.view} className="pointer-events-none absolute inset-0 overflow-hidden" style={{ visibility: "hidden" }}>712 <div ref={layer.camera} className="absolute left-0 top-0" style={{ transformStyle: "preserve-3d" }}>713 {children}714 </div>715 </div>716 );717}718719interface LayerCardProps extends Partial<TestimonialCardProps> {720 layer: CardLayer;721 index: number;722 /** A repeated copy (rings, ribbons): hidden from screen readers so each quote is read once. */723 duplicate?: boolean;724 onSelect?: () => void;725 onHover?: (hovered: boolean) => void;726 /** A card of your own instead of TestimonialCard (the anchor's `px` must match its width). */727 children?: ReactNode;728}729730/** One card of the layer, placed every frame on its anchor. */731function LayerCard({ layer, index, duplicate = false, onSelect, onHover, children, ...card }: LayerCardProps) {732 return (733 <div734 ref={(el) => {735 layer.elements.current[index] = el;736 }}737 aria-hidden={duplicate ? true : undefined}738 className="absolute left-0 top-0 rounded-2xl outline-none focus-visible:ring-2 focus-visible:ring-white/70"739 style={{ pointerEvents: onSelect || onHover ? "auto" : "none", cursor: onSelect ? "pointer" : undefined, transformStyle: "preserve-3d", willChange: "transform" }}740 role={onSelect ? "button" : undefined}741 tabIndex={onSelect && !duplicate ? 0 : undefined}742 onClick={onSelect}743 onKeyDown={744 onSelect745 ? (event) => {746 if (event.key === "Enter" || event.key === " ") {747 event.preventDefault();748 onSelect();749 }750 }751 : undefined752 }753 onPointerEnter={onHover ? () => onHover(true) : undefined}754 onPointerLeave={onHover ? () => onHover(false) : undefined}755 >756 {children ?? (card.item && card.accent && card.theme ? <TestimonialCard item={card.item} accent={card.accent} theme={card.theme} text={card.text} /> : null)}757 </div>758 );759}760761/** Page scroll velocity, px per second, smoothed. Read it in useFrame. */762function useScrollVelocity() {763 const velocity = useRef(0);764 useEffect(() => {765 let last = window.scrollY;766 let lastT = performance.now();767 const onScroll = () => {768 const now = performance.now();769 const dt = Math.max(8, now - lastT) / 1000;770 velocity.current = velocity.current * 0.5 + ((window.scrollY - last) / dt) * 0.5;771 last = window.scrollY;772 lastT = now;773 };774 window.addEventListener("scroll", onScroll, { passive: true });775 return () => window.removeEventListener("scroll", onScroll);776 }, []);777 return velocity;778}779780export type PerspectiveDualWallMarqueeProps = DeepTestimonialProps;781782const CARD_W = 2.4;783const GAP = 0.3;784const PITCH = CARD_W + GAP;785const ROW_GAP = 1.9; // between the two rows' centers786const WALL_LENGTH = 18; // world units a row must cover, beyond the visible width787const BASE_SPEED = 0.55; // units per second at speed 1788const SCROLL_BOOST = 1 / 450; // extra speed per px/s of page scroll789790interface RowCard {791 item: TestimonialItem;792 key: string;793 duplicate: boolean;794 row: 0 | 1;795 slot: number;796}797798/** Two rows long enough to loop seamlessly; the second starts halfway through the list so they differ. */799function buildRows(items: TestimonialItem[]) {800 if (!items.length) return { cards: [] as RowCard[], perRow: 0 };801 const perRow = Math.max(Math.ceil(WALL_LENGTH / PITCH), items.length);802 const seen = new Set<string>();803 const cards: RowCard[] = [];804 for (const row of [0, 1] as const) {805 const start = row === 0 ? 0 : Math.floor(items.length / 2);806 for (let slot = 0; slot < perRow; slot++) {807 const item = items[(start + slot) % items.length];808 cards.push({ item, key: `${row}-${slot}-${item.id}`, duplicate: seen.has(item.id), row, slot });809 seen.add(item.id);810 }811 }812 return { cards, perRow };813}814815interface Flow {816 offset: [number, number];817 velocity: number;818 hovered: number;819}820821interface WallProps {822 cards: RowCard[];823 perRow: number;824 variant: Variant;825 surface: string;826 accent: string;827 speed: number;828 still: boolean;829 interactive: boolean;830 flow: RefObject<Flow>;831 layer: CardLayer;832 mobile: boolean;833}834835function Wall({ cards, perRow, variant, surface, accent, speed, still, interactive, flow, layer, mobile }: WallProps) {836 const groups = useRef<(THREE.Group | null)[]>([]);837 const slabs = useRef<(SlabHandle | null)[]>([]);838 const scroll = useScrollVelocity();839 const camera = useThree((s) => s.camera);840 const length = perRow * PITCH;841842 const bindings = useMemo(843 () =>844 cards.map((_, i) => ({845 group: (g: THREE.Group | null) => {846 groups.current[i] = g;847 },848 slab: (api: SlabHandle) => {849 slabs.current[i] = api;850 },851 })),852 [cards]853 );854855 useEffect(() => {856 camera.position.set(0, 0, mobile ? 14 : 9.5);857 camera.lookAt(0, 0, 0);858 }, [camera, mobile]);859860 useFrame((_, delta) => {861 const dt = Math.min(delta, 1 / 30);862 const f = flow.current;863 // Page scroll speeds the rows up (and scrolling back up runs them backwards for a moment)864 const fromScroll = interactive ? THREE.MathUtils.clamp(scroll.current * SCROLL_BOOST, -6, 6) : 0;865 const hoverSlow = f.hovered >= 0 ? 0.15 : 1;866 const target = still ? 0 : BASE_SPEED * speed * (1 + fromScroll) * hoverSlow;867 f.velocity = THREE.MathUtils.damp(f.velocity, target, 4, dt);868 scroll.current = THREE.MathUtils.damp(scroll.current, 0, 3, dt);869 f.offset[0] += f.velocity * dt;870 f.offset[1] -= f.velocity * dt;871872 for (let i = 0; i < cards.length; i++) {873 const c = cards[i];874 // Wrap around: x in [-length/2, length/2)875 const raw = c.slot * PITCH + f.offset[c.row];876 const x = (((raw % length) + length) % length) - length / 2;877 const g = groups.current[i];878 if (g) g.position.set(x, c.row === 0 ? ROW_GAP / 2 : -ROW_GAP / 2, 0);879880 // Cards fade in and out at the ends of the loop; the one crossing the light's beam glows881 const ends = 1 - THREE.MathUtils.smoothstep(Math.abs(x), length / 2 - PITCH * 2.2, length / 2 - PITCH * 0.6);882 const beam = 1 - THREE.MathUtils.smoothstep(Math.abs(x), 0, PITCH * 0.8);883 slabs.current[i]?.setOpacity(ends);884 slabs.current[i]?.setHighlight(f.hovered === i ? 1 : beam * 0.8);885 const el = layer.elements.current[i];886 if (el) el.style.opacity = String(ends);887 }888 });889890 return (891 <group rotation={[-0.2, -0.38, -0.04]} position={[0.4, 0.1, 0]}>892 {/* The virtual light at the center of the screen: the card edges flare as they cross it */}893 <pointLight position={[0, 0, 1.6]} intensity={14} distance={6} decay={2} color="#ffffff" />894 <pointLight position={[0, 0, 0.8]} intensity={4} distance={3.5} decay={2} color={accent} />895 {cards.map((c, i) => (896 <group key={c.key} ref={bindings[i].group}>897 <Slab width={CARD_W} finish="porcelain" variant={variant} surface={surface} accent={accent} depth={0.12} handle={bindings[i].slab}>898 <CardAnchor layer={layer} index={i} width={CARD_W} z={0.07} />899 </Slab>900 </group>901 ))}902 </group>903 );904}905906/**907 * Two endless ribbons of porcelain testimonial cards (glazed, or frosted white acrylic when "glass"),908 * dark ink on white, sliding in opposite directions across a wall tilted in space.909 * A light at the center of the screen sweeps the card edges as they cross it; scrolling the page speeds910 * the ribbons up, hovering a card slows them down so it can be read.911 */912export default function PerspectiveDualWallMarquee({913 items,914 interactive = TESTIMONIAL_DEFAULTS.interactive,915 variant = "solid",916 speed = TESTIMONIAL_DEFAULTS.speed,917 accentColor = "#c084fc",918 surfaceColor = "#f2eff6",919 textColor = "#17151d",920 className = "",921}: PerspectiveDualWallMarqueeProps) {922 const flow = useRef<Flow>({ offset: [0, 0], velocity: 0, hovered: -1 });923 const reduced = usePrefersReducedMotion();924 const mobile = useIsMobile();925 const layer = useCardLayer();926 const { cards, perRow } = useMemo(() => buildRows(items), [items]);927928 const hover = useCallback((i: number, on: boolean) => {929 const f = flow.current;930 f.hovered = on ? i : f.hovered === i ? -1 : f.hovered;931 }, []);932 const hovers = useMemo(() => cards.map((_, i) => (on: boolean) => hover(i, on)), [cards, hover]);933934 return (935 <section aria-label="Customer testimonials" className={`relative h-[min(84svh,760px)] min-h-[520px] w-full overflow-hidden ${className}`}>936 <TestimonialCanvas camera={{ fov: 35, near: 0.1, far: 100 }}>937 <StudioLights accent={accentColor} />938 <Wall cards={cards} perRow={perRow} variant={variant} surface={surfaceColor} accent={accentColor} speed={speed} still={reduced} interactive={interactive} flow={flow} layer={layer} mobile={mobile} />939 <CardLayerSync layer={layer} />940 </TestimonialCanvas>941 <CardLayerView layer={layer}>942 {cards.map((c, i) => (943 <LayerCard key={c.key} layer={layer} index={i} item={c.item} accent={accentColor} theme="porcelain" text={textColor} duplicate={c.duplicate} onHover={interactive ? hovers[i] : undefined} />944 ))}945 </CardLayerView>946 </section>947 );948}
03
Drop it in a page
Updated live with the settings above.
app/page.tsx
1import PerspectiveDualWallMarquee from "@/components/PerspectiveDualWallMarquee";23export default function Section() {4 return (5 // The component fills this box: give it a position and a height6 <div style={{ position: "relative", width: "100%", height: "100vh" }}>7 <PerspectiveDualWallMarquee8 variant="solid"9 speed={1}10 accentColor="#c084fc"11 surfaceColor="#f2eff6"12 textColor="#17151d"13 interactive14 items={testimonials}15 />16 </div>17 );18}