Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

React
  • Backend vs Frontend: What Runs Where, and Why the Server Is the One You Trust
  • One Request, Two Answers: the Same Post as an HTML Page and as JSON
  • A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
  • How a Web Page Works: HTML Tags, Elements and Attributes
  • Semantic HTML: header, nav, main, aside and footer as Page Landmarks
  • HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
  • CSS Basics: Selectors, Which Rule Wins, and the Box Model
  • CSS Flexbox vs Grid: A Nav Bar, a Card Row and a Dashboard
  • Responsive CSS: Viewport, Mobile-First Media Queries, clamp() and Dark Mode with Tokens
  • JavaScript for People Who Already Code: Syntax, Modules and Five Surprises
  • JavaScript Arrays the Functional Way: map, filter, reduce, find, sort and Object.entries
  • Async JavaScript: Promises, async/await, fetch and Promise.all
  • JavaScript in the Page: the DOM, querySelector and Events
  • npm, package.json and Vite: What npm install Fetches and How Vite Serves and Builds Your Page
  • TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
  • Why React, JSX and Components: The Page as a Function of Data
  • React Props and Composition: Data Down, Calls Up, Children in the Slot
  • Routing With React Router: One Page, Many Addresses
  • React Component Tests With Vitest and Testing Library: Test What the User Sees
  • End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal
  • Why AI-Built Websites All Look the Same, and Four Levels That Fix It
  • Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
  • Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
  • Typography That Sells: Type Scale, Line Length and Free Font Pairings
  • The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
  • Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
  • Tailwind CSS 4 in React: Utility Classes, Responsive Prefixes, Hover and Dark Mode
  • shadcn/ui in React: Components You Own, Edit and Commit
  • Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
  • Motion in React: Entrance, Hover, Exit and Layout Animations
  • A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
  • Accessibility in Practice: Dialogs, Menus and the Keyboard in React
  • Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
  • Components, Variants and Variables: One Design System in Figma and in CSS
  • Figma MCP Server: Build a React Component From a Frame, Then Write It Back
  • Claude Design: From a Brief to a Clickable Prototype, Then Hand It Off to Claude Code
  • Critiquing AI-Generated UI: Six Checks for Every Screen
  • The AI Design Landscape: Prompt to UI, Prompt to App, and Design to Code
  • Your Brand Rules Folder: One Folder Every AI-Built Page Follows
  • The Best-Practice UI Prompt: Plain Sentences That Beat the Average AI Page
  • UI Ideas From Figma Make, Google Stitch and ChatGPT: One Prompt, Three Designs
  • Google Stitch From a Sketch or Screenshot: Show the Layout, Say What to Keep
  • Stitch to Figma to Code: Turn a Stitch Screen Into Code That Uses Your Tokens
  • Figma Make: Prompt to Prototype With a Four-Part Prompt
  • Upgrade a Dated UI From One Screenshot (or a Reference Image)
  • States and Feedback: Make Every Click Get an Answer
  • A Design-Loop Skill: Claude Screenshots, Scores and Fixes Its Own UI
  • Copy Without the AI Tells: A Copy Pass on a Landing Page
  • Running a Next.js Admin Starter Kit: Route Groups, Theme Tokens and npm run dev
  • Remotion Basics: A Video as One Composition Object, Frames, Sequences and the Player
  • Spline: Put a 3D Scene on a Landing Page Without Writing 3D Code
  • Framer: A Launch Page Without Code, From a Free Animated Template
  • Three.js: What It Can Do on Real Sites, and How to Let Your AI Agent Use It
  • Animated Component Libraries (Magic UI, Aceternity UI): Copy-In Motion and When It Becomes Noise
  • WebGPU and Three.js Shaders in TSL: A Living Gradient, 4,500 Particles and a Hover Ripple
  • Deploy Many Vite Demos as One Static Site: A Gallery Page, One Build Command and import.meta.env.BASE_URL
  • React State, Events, Lists and Conditional Rendering: Follow One Click
  • React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
  • Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
  • Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
  • React Context and Custom Hooks: Share One Value, Reuse the Logic
  • Finishing a Remotion Video Editor: Timeline Sync, Track Order, Trims and Fades, and the Server MP4 Render
  • A 3D Product Page in React and Three.js: Scroll Becomes a Number, One Camera Shot per Panel, One Choice Drives Everything
  • A Personal 3D Portfolio Room in React Three Fiber: Hover Glow, Click to Open, Pointer Drift and a Contact Form to FastAPI
  • Server State With TanStack Query: One Key, One Request, One Cache
  • Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
  • Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
  • A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
  • A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
  • Forms With React Hook Form and Zod: The API's Rules in the Browser, the Server's Errors Under the Field
  • JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
  • Supabase as a Backend: Postgres, Instant APIs, Row Level Security and the Two Keys
  • Email Login With Supabase in Next.js: Three Clients, Server Actions, the Callback Route and Middleware
  • Google Sign-In With Supabase in Next.js: Which Address Goes Where
  • hCaptcha on a Supabase Login Page: Site Key in the Browser, Secret in Supabase
  1. Blog
  2. /
  3. React
  4. /
  5. Hooks

A 3D Product Page in React and Three.js: Scroll Becomes a Number, One Camera Shot per Panel, One Choice Drives Everything

Aurel One, a fictional pair of headphones built from plain three.js shapes, turns as you scroll, frames each feature with its own camera pose, repaints with 1 - e^(-dt*5) colour blending, and keeps a sticky buy box in sync, all from one scroll ref and one finish state. Phones get a still until they tap View in 3D.

Chaand Sheikh

·27 November 2026·Updated 29 November 2026Hooks

What you will learn

  • Turn scroll position into a progress number kept in a ref, so the 3D scene reads it every frame without React re-renders
  • Blend between camera poses and damp toward them so the model glides
  • Build a model from simple shapes (tube, lathe, torus) and blend finish colours frame by frame
  • Drive the model, swatches and buy box from one piece of state, and lazy-load the 3D for phones

Before you start

  • React useState, useRef and useEffect
  • Three.js: what it can do

This is the kind of page brands pay agencies for: a 3D product page. Spin it, scroll it, buy it. A pair of headphones sits in the middle of the screen. You scroll, and they turn to show the part being described. You pick a colour, and they repaint. We cover the foundations: you don't have to memorise every line, but you should know what each part does so the code makes sense when the page grows.

The product is Aurel One, a fictional pair of headphones, built from simple three.js shapes, so there's no model file to download. The project uses React with React Three Fiber.

Aurel One product page on desktop: a large Aurel One wordmark behind 3D headphones in the Graphite finish, the headline Quiet, carved from aluminium, and a buy box on the right with price, four finish swatches and an Add to bag button.
The hero pose, from the showcase gallery's capture of the page: model in the middle, sticky buy box on the right.

One page, four tricks

  1. Spin: the model turns as you scroll.
  2. Repaint: a swatch blends a new colour into the model.
  3. Buy: a buy box stays with you while you scroll, so the button is always one click away.
  4. Fast: phones get a light version, so the page loads quickly.

Spin: scroll becomes a number

At the top the headphones sit in their hero pose. Scroll a little and they start turning; at the Sound panel you're looking at the driver side. All of it is driven by one number, from useStoryProgress.ts:

export function useStoryProgress(el: RefObject<HTMLElement | null>, steps: number) {
  const progress = useRef(0)
  const [active, setActive] = useState(0)

  useEffect(() => {
    let frame = 0
    const update = () => {
      frame = 0
      const box = el.current?.getBoundingClientRect()
      if (!box) return
      const t = Math.min(1, Math.max(0, -box.top / (box.height - innerHeight)))
      progress.current = t * steps
      el.current!.style.setProperty('--p', String(progress.current))
      setActive(Math.round(progress.current)) // React skips the render when the number did not change
    }
    const onScroll = () => { if (!frame) frame = requestAnimationFrame(update) }
    update()
    addEventListener('scroll', onScroll, { passive: true })
    addEventListener('resize', onScroll)
    return () => { removeEventListener('scroll', onScroll); removeEventListener('resize', onScroll); cancelAnimationFrame(frame) }
  }, [el, steps])

  return { progress, active }
}

Ask where the story section is (box.top), divide by the section height minus the window height, and clamp between 0 and 1. Multiply by the number of steps and you get progress from 0 to 4. The exact value goes to three places:

One scroll number, three destinations scroll -box.top / (h - innerHeight) progress.current (ref) read by useFrame every frame, no re-render --p (CSS variable) scroll-linked CSS, like the fading wordmark active (state, rounded) which panel is lit; renders only when it changes
Scrolling never re-renders React for the 3D: the scene reads a ref.

Scroll it: one camera shot per panel

Each panel gets its own pose. A pose is a few numbers: rot turns the model, scale zooms, focus is the point we want to look at, and at is where that point lands on screen.

export const POSES: Pose[] = [
  { rot: [0.22, -0.62, 0], focus: [0, 0.1, 0], at: [0.35, -0.15, 0], scale: 0.8 }, // hero
  { rot: [0.12, -1.2, 0.05], focus: [1.15, -0.62, 0], at: [0.95, -0.05, 0], scale: 1.25 }, // Sound: driver side
  { rot: [0.55, 0.62, 0], focus: [0, 0.4, 0], at: [0.8, -0.1, 0], scale: 0.95 }, // Comfort: headband pad + cushions
  { rot: [-0.75, -1.25, 0], focus: [1.05, -1.1, 0], at: [0.85, 0.15, 0], scale: 1.35 }, // Battery: port + LED under the right cup
  { rot: [0.05, 1.35, -0.05], focus: [-1.15, -0.62, 0], at: [0.8, -0.05, 0], scale: 1.25 }, // ANC: microphones on the left cup
]

For the Sound panel, scale is 1.25 and the focus sits at the driver side. Inside useFrame, the rig blends between the two nearest poses and then chases the target:

  useFrame((state, dt) => {
    const p = reduced ? 0 : progress.current
    const i = Math.min(Math.floor(p), POSES.length - 2)
    // hold each pose for the middle of its panel, move in between
    const t = smooth(Math.min(1, Math.max(0, (p - i - 0.2) / 0.6)))
    const a = POSES[i], b = POSES[i + 1]
    // ... lerp rot, focus, at and scale from a to b by t ...
      easing.dampE(g.rotation, [T.rot[0] + idle, T.rot[1], T.rot[2]], 0.35, dt)
      easing.damp(g.scale, 'x', T.scale, 0.35, dt)
    // ...
    else easing.damp3(g.position, goal, 0.25, dt)
  })

Each pose is held for the middle of its panel, with movement in between. dampE chases the target rotation a little on every frame. That's why it feels smooth: the model never jumps, it glides, and it feels heavy, like a real product in your hand.

Headphones from simple shapes

  • Headband: a TubeGeometry that follows an arc. Stretched on the z axis (the lecture's slide uses scale z 2.1), the round tube becomes a wide, flat band.
  • Ear cup: a LatheGeometry. Give it a side profile, CUP_PROFILE, and three.js spins it around to make a smooth cup.
  • Cushion: a torusGeometry, a donut, squashed a little with scale={[1, 1, 0.7]}.

Stretch a tube and you get a headband. Spin a profile and you get an ear cup.

Repaint it: a swatch blends the colour in

Each finish is one line in finishes.ts: a body colour, a metal colour, a cushion colour, and a UI colour for the page accent. The project has four (the lecture slide shows three of them):

export const FINISHES: Finish[] = [
  { id: 'graphite', name: 'Graphite', body: '#3b3b3e', metal: '#a4a7ad', cushion: '#2a2a2d', ui: '#c9ccd3' },
  { id: 'sand', name: 'Sand', body: '#cbbda5', metal: '#c9a476', cushion: '#a8977d', ui: '#e6c99a' },
  { id: 'sage', name: 'Sage', body: '#86957f', metal: '#cfd3c6', cushion: '#5f6c5b', ui: '#b9cdae' },
  { id: 'midnight', name: 'Midnight Blue', body: '#1e2a46', metal: '#b48d5e', cushion: '#18203a', ui: '#93aee6' },
]

Every frame, the model moves its colours toward the target:

    const k = instant ? 1 : 1 - Math.exp(-dt * 5)
    m.body.color.lerp(target.body, k)
    m.metal.color.lerp(target.metal, k)
    m.grille.color.lerp(target.metal, k)
    m.cushion.color.lerp(target.cushion, k)

k = 1 - e^(-dt*5) is a frame-rate-independent step. The colour doesn't snap; it moves a little closer every frame, and the page accent follows. Want a slower blend? Make the 5 smaller. Now you know exactly what to ask AI for.

Buy it: one choice drives everything

The buy box has the finish swatches, the price and an Add to bag button; clicking it shows a small toast. It all runs on one piece of state in App.tsx:

  const [finish, setFinish] = useState<Finish>(() => FINISHES.find((f) => f.id === params.get('finish')) ?? FINISHES[0])
  // ...
  const buy = { finish, onFinish: setFinish, onAdd: addToBag }

The Scene gets the finish. The buy box sits in a sticky div as tall as the screen, so it stays beside you while you scroll:

<div className="sticky top-0 flex h-dvh items-center px-8 pt-16"><BuyBox {...buy} /></div>

One choice feeds the 3D model, the swatches, the buy box and the accent colour. That's why it feels like one product and not four separate widgets.

A still first, 3D on request

3D is heavy. On a phone you get a still image of the headphones in your chosen colour; tap View in 3D and the scene loads.

// three.js + the model live in this lazy chunk: phones without "View in 3D" never download it.
const Scene = lazy(() => import('./Scene'))
// ...
  const small = useMedia('(max-width: 767px)')
  const [webgl] = useState(hasWebGL)
  const [wants3D, setWants3D] = useState(false)
  const show3D = webgl && (!small || wants3D)

lazy means the three.js code isn't downloaded until the 3D is shown. show3D is true when WebGL is there and either the screen isn't small or the visitor asked for it. The still loads in a blink, and the visitor decides when to pay for 3D.

Showy, but kind to the visitor

  • Reduced motion: the model holds the hero pose and all the text is visible (const p = reduced ? 0 : progress.current).
  • Real buttons: the swatches are radio buttons, with names and a 44-pixel tap target.
  • No downloads at runtime: fonts are bundled, and the lighting comes from local light panels.

Quick recap

TrickKey idea
SpinScroll to 0..4 in a ref, read by useFrame
Scroll itPOSES blended by progress, damped with maath/easing
ModelTube, lathe and torus, no model file
Repaintcolor.lerp(target, 1 - Math.exp(-dt * 5))
BuyOne finish state, sticky buy box
Fastlazy(() => import('./Scene')), a still on phones

Try it yourself

Edit a pose in POSES to frame a different part. Add a fifth finish. Change dt * 5 to make the blend slower. Any editor works: VS Code, IntelliJ, even Notepad. The project files and prompts are in the community, free to join.

Tried the exercise? Share your answer or ask a question.

The StudyEasy AI Community is free to join, with the lesson files, notebooks and code.

Join free on Skool

Keep going in React · 63 of 75

Previous
Finishing a Remotion Video Editor: Timeline Sync, Track Order, Trims and Fades, and the Server MP4 Render
Next post
A Personal 3D Portfolio Room in React Three Fiber: Hover Glow, Click to Open, Pointer Drift and a Contact Form to FastAPI

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

React State, Events, Lists and Conditional Rendering: Follow One Click

Follow one click through a React counter, render by render: what useState hands back, why a plain variable never updates the page, ternaries and &&, map with keys, and the index-as-key bug that moves a typed note to the wrong task.

React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One

Watch useEffect on a timeline with real render counts: the dependency array deciding re-runs, a timer cleanup that keeps one timer alive, the leak StrictMode exposes, and two effects you should delete (a copied total and a click flag).

Lifting State Up, Refs and React DevTools: Put State Where It Is Needed

A task board where the filter is stuck in one component, fixed by lifting it to App. Then useRef as a box React does not watch (three clicks, zero renders), a ref that refocuses an input, and the tree React DevTools shows.

Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus

Four versions of an add-task form, traced with real logs: a controlled input, a classic onSubmit, a form action that gets FormData and resets itself, and useActionState with a pending button from useFormStatus, plus the draft trick that keeps typed text after an error.

On this page

  • One page, four tricks
  • Spin: scroll becomes a number
  • Scroll it: one camera shot per panel
  • Headphones from simple shapes
  • Repaint it: a swatch blends the colour in
  • Buy it: one choice drives everything
  • A still first, 3D on request
  • Showy, but kind to the visitor
  • Quick recap
  • Try it yourself
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.