webdevpuneet.com

Three.js Scroll Book: 3D Page Flip With Real Pages

Three.js Scroll 3D Book Page Flip · Scroll · Plain HTML, CSS & JS · Live preview

About this UI Snippet

Build a Scroll-Driven 3D Book in Three.js: Cover, Curling Pages and a Printed Story

Screenshot of the Three.js Scroll 3D Book Page Flip snippet rendered live

The Three.js Scroll 3D Book snippet puts a purple hardcover on a lamp-lit desk. Scrolling opens the cover, then turns eight leaves of a short illustrated story, *The Lantern Keeper*, one after another. Each page carries printed text on both sides, the paper curls as it turns, and the lamp casts real shadows onto the pages below. GSAP's ScrollTrigger pins the scene and scrubs a single progress value from 0 to 1; every cover angle, page curl, camera move and HUD label is a pure function of that number, so scrolling backwards un-reads the book exactly.

Pages printed with canvas textures

Every side of every leaf is drawn into a 480 × 660 canvas at load: paper colour with fibre specks, a darker gutter on the spine side, a running head, a folio, and the content itself. Body text is justified word by word, chapter openings get a three-line drop cap, and four ink illustrations (a lighthouse, a storm over the reef, a sunrise and a lantern) are drawn with canvas paths, so the whole book ships with no image files. To print your own book, edit the P paragraphs and the SIDES list: each entry is a title page, epigraph, chapter opening, text page, captioned illustration, end page or colophon.

Two meshes, one bending geometry

A plane can only show one texture, but a leaf has two printed sides. Each leaf therefore shares one PlaneGeometry between two meshes: the recto with FrontSide and the verso with BackSide, its texture mirrored with repeat.x = -1 so the text reads correctly once the page lands on the left. The geometry is translated so its left edge sits on the spine, which turns plain rotation.z into a page turn. While a leaf is in the air its vertices are rewritten from a stored flat copy: the middle bows and the free edge trails behind, and the curl falls back to zero when the leaf lies flat, so nothing accumulates.

Cover, stacks and leafing rhythm

The front cover is a leather box with a gold-stamped title on top and patterned endpaper underneath. It turns first, lifting slightly as it swings, and lands under the left stack. Leaves start their turn when the previous one is 60% across, so two pages are often in the air together, the way a reader leafs through. Each leaf's height glides from the right stack order to the mirrored left stack order as it turns, so the right pile thins and the left pile grows.

Lamp light, shadows and a reading camera

A warm SpotLight with soft PCF shadows lights the desk. A turning page throws a moving shadow across the page underneath, which does more for realism than any texture. ACES filmic tone mapping keeps the paper from blowing out under the lamp, and warm dust drifts through the light. The camera starts close on the closed cover, rises to a reading view as it opens and eases back at the end. On tall phone screens it pulls back, and the fog distance scales with it, so the open book always fits.

Navigation and accessibility

The HUD shows the current chapter, a gold progress bar and the page count ("Pages 6–7 / 16"). The ‹ › buttons and the arrow or Page Up/Down keys scroll to the next cover or page stop, so the book can be read without a scroll wheel. The page label is an aria-live region, the canvas is hidden from screen readers, and with prefers-reduced-motion the scrub has no smoothing and the camera and dust stay still. For other scroll-driven Three.js scenes, see the ocean dive and the voxel build; for 2D chapters, try the scroll pin story.

What's included

Features

Leather hardcover with a gold-stamped title that opens first and becomes the left board
Eight leaves with print on both sides: recto and verso meshes share one bending geometry
Pages drawn on canvas: justified text, drop caps, running heads, folios and gutter shading
Four ink illustrations drawn with canvas paths, so the book needs no image files
Curling paper: the middle bows and the free edge trails, then the page lies flat again
Lamp SpotLight with soft shadows, filmic tone mapping and warm dust drifting in the light
Chapter HUD with a progress bar, a live page count and ‹ › buttons with arrow-key support
Camera and fog fit tall phone screens; reduced motion removes the smoothing, camera drift and dust

Step by step

How to Use

  1. 1
    Load the three CDN scriptsAdd three.min.js (r128), gsap.min.js and ScrollTrigger.min.js, in that order, before the snippet JS.
  2. 2
    Paste the HTML, CSS and JSA closed hardcover lies on a lamp-lit desk with the title overlay above it and the chapter HUD at the bottom.
  3. 3
    Scroll to open and readThe cover swings open, then eight leaves turn with curling paper and moving shadows while the HUD follows the chapters.
  4. 4
    Use the page buttons or keysPress ‹ › in the HUD or the arrow keys to jump to the next page stop. Scrolling up turns pages back in order.
  5. 5
    Write your own bookReplace the P paragraphs and the SIDES list, change TITLE and the cover text in leatherTexture, and adjust LEAF to set the page count.
  6. 6
    Tune the feelChange the end value (+=600%) for a longer read, the 0.6 overlap in leafStart for faster leafing, or the lamp colour and angle.

Real-world uses

Common Use Cases

Author and publisher launch pages
Give a new novel a landing page where visitors open the cover and read the first chapter in place, then reach the buy links in the section that follows.
Brand stories and annual reports
Tell a founding story or a year in review as four short chapters, with illustrations of the product in place of the lighthouse and the storm.
Wedding and memory books
Swap the story for a couple's timeline or a family album: chapter pages for each year, captioned drawings or photos, and a closing page with the date.
Learning canvas textures and vertex bends
One scene covers justified canvas typography, double-sided meshes, hinge-translated geometry, vertex curls restored from a base copy and shadowed lighting.

Got questions?

Frequently Asked Questions

Each leaf uses two meshes that share one PlaneGeometry. The recto material renders FrontSide with the right-hand page texture, and the verso renders BackSide with the left-hand texture mirrored by repeat.x = -1. Because the geometry is shared, the curl applied to its vertices moves both sides together.

Every side is drawn into its own canvas at load and used as a CanvasTexture. A small justify function measures each word and spreads the spacing so lines end flush, leaving room for a three-line drop cap on chapter pages. Edit the P paragraphs and the SIDES list to print your own content.

While a leaf is turning, its vertices are rewritten from a flat copy with an offset of sin(turn × π) × (0.55 · sin(uπ) − 1.6 · u²), where u runs from the spine to the free edge. The middle bows and the free edge trails behind. At rest the offset is zero, so the page lies flat again.

Yes. The ‹ › buttons and the arrow or Page Up/Down keys scroll the page to the next stop: closed, cover open, then each leaf landed. The page count is an aria-live region, so screen readers announce it. With reduced motion turned on, the scroll is not smoothed and the camera and dust stay still.

Yes. Export it with the framework buttons and create the renderer, textures and ScrollTrigger in a mount effect against a canvas ref. On cleanup, kill the ScrollTrigger, remove the resize and keydown listeners, dispose the geometries, materials and the 16 canvas textures, and call renderer.dispose().

Copy & paste

Source Code

<section class="bkp-stage" id="bkpStage" aria-label="A 3D book that turns its pages as you scroll">
  <canvas id="bkpCanvas" aria-hidden="true"></canvas>
  <div class="bkp-intro" id="bkpIntro">
    <p class="bkp-kicker">A short story in four chapters</p>
    <h2 class="bkp-title">The Lantern Keeper</h2>
    <p class="bkp-hint"><span class="bkp-mouse" aria-hidden="true"></span>Scroll to open the book</p>
  </div>
  <div class="bkp-hud">
    <p class="bkp-chapter" id="bkpChapter">The Lantern Keeper</p>
    <div class="bkp-bar" aria-hidden="true"><span id="bkpBar"></span></div>
    <div class="bkp-nav">
      <button type="button" id="bkpPrev" aria-label="Previous page">&#8249;</button>
      <span class="bkp-count" id="bkpPage" aria-live="polite">Cover</span>
      <button type="button" id="bkpNext" aria-label="Next page">&#8250;</button>
    </div>
  </div>
</section>
<section class="bkp-after">
  <p class="bkp-after-kicker">Light kept.</p>
  <p>Scroll back up and the pages turn back, one by one.</p>
</section>

Extend with AI

Take This Snippet Further With AI

Paste this snippet's HTML, CSS and JS into an AI assistant like Claude and ask it to walk you through the parts you want to reuse: why two meshes share one geometry, how the justify function lays out text on a canvas, or how the curl formula keeps the free edge trailing. It can also take the book further: loading real photos into the illustration slots, a page-turn sound timed to each landing, letting readers drag a page corner to turn it, a table of contents page whose entries jump to chapters, or a second book on the shelf that slides into place for volume two.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a scroll-driven 3D book in plain HTML, CSS and JavaScript with Three.js r128, GSAP and ScrollTrigger loaded from a CDN (no build step).

Requirements:
- A pinned full-viewport section (ScrollTrigger pin, scrub 0.6, end +=600%) with a canvas, a title overlay ("Scroll to open the book" with a mouse icon) that fades out once scrolling starts, and a glassy bottom HUD showing the chapter name, a gold progress bar, a page count ("Pages 6–7 / 16") in an aria-live region, and ‹ › buttons.
- Renderer: sRGB output, ACES filmic tone mapping, PCF soft shadows. A dark wood desk (canvas texture), fog, a hemisphere fill and a warm SpotLight lamp casting soft shadows.
- A leather hardcover: a back board under the right stack, a half-cylinder spine and a front cover box translated so its left edge sits on the spine. The top face has a gold-stamped title, border and lantern drawn on canvas; the bottom face has patterned endpaper (mirrored). The cover turns first (progress 0 to 0.09), lifting slightly mid-swing and landing under the left stack.
- 8 leaves. Each is one PlaneGeometry (28 width segments) rotated flat and translated so the left edge is the hinge, shared by two meshes: a recto (FrontSide) and a verso (BackSide, texture mirrored with repeat.x = -1).
- 16 page sides drawn into 480×660 canvases: paper with fibre specks, gutter shading on the spine side, a running head and folio. Content types are a title page, epigraph, chapter opening with a three-line drop cap and justified text, text page, captioned ink illustration (lighthouse, storm, sunrise, drawn with canvas paths), end page and colophon. The story is "The Lantern Keeper" in four chapters.
- Leaf i turns across its window of the page phase (0.09 to 0.93), starting when leaf i−1 is 60% across, with easeInOutQuad and rotation.z = π × eased. Its height glides from the right stack order to the mirrored left stack order.
- Curl while turning: rewrite vertices from a stored flat copy with y += sin(eased·π) × (0.55·sin(uπ) − 1.6·u²), then computeVertexNormals(). Skip the work when a leaf is flat.
- Camera: close on the closed cover, rising to a reading view as it opens and easing back at the end. Pull back on tall screens and scale the fog distance with it.
- ‹ › buttons and arrow / Page Up / Page Down keys scroll to the next stop (closed, cover open, each leaf landed). Disable the buttons at either end.
- Warm additive dust points drifting in the lamp light. prefers-reduced-motion: no scrub smoothing, no camera drift, still dust, no wheel animation.
- Scrolling backwards must un-turn everything in exact reverse order.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.