Pop-up book of live HTML cutouts

I wanted to know if a paper pop-up book can be made of live HTML: a story spread whose cutouts stand up on synchronised hinges as the book opens, while the buttons and the <details> printed on each cutout stay clickable at every fold angle. Drag the open angle, share a dango, or tap an animal.

Starting Three.js WebGL scene...

Momotarō, chapter two

The peach boy sets out

Grown strong, Momotarō packed three kibi dango and set out for Onigashima.

Party: Momotarō
p. 6

Share dango to gather the party, then set sail.

Onigashima

Ogre island, across the sea.

Gate: closed
Momotarō Kibi dango: 3
Show the code fold kinematics, HTMLSurfaces cutouts and the edge scan check
  1. One Three.js canvas. HTMLSurfaces moves the story page, the riverbank page and the three cutouts into the canvas as drawable children and uploads each with texElementSubImage2D().
  2. Cutouts are plain elements with a fixed size. The die-cut silhouettes are clip-path and border-radius; transparent pixels are dropped with alphaTest on the plane.
  3. Synchronised fold angles. Each cutout's top edge rides just under the turning page, so its raise angle comes from the open angle by intersecting a ray with the hinge circle.
  4. Hinges and pages. Every cutout hangs from a hinge group on the floor page; surfaces.update() calls updateElementGeometry() each frame so the browser's hit test follows the raised plane.
  5. Edge scan. The live check walks elementFromPoint() along the projected centre line of a button and compares where hits start and stop with the drawn edges.

How it works

This experiment takes inspiration from Thomas Nattestad's Momotarō Pop-Up Book in html-in-canvas-fun. The spread is five ordinary elements: an <article> story page, a riverbank page, and three cutouts carrying live <button> and <details> elements. Without HTML-in-canvas or WebGL they stay in the page as a plain column.

With both, Three.js draws each element on a plane through HTMLSurfaces from /lib/html3d.js. The story page turns about the spine at the open angle. Each cutout is hinged on the floor page at its own distance from the spine, and its top edge is held a few degrees under the turning page, the way a paper strip pulls a real pop-up up. That gives every cutout its own raise angle from one slider: the companions stand first, Momotarō next, and the island last, all upright by about 70 degrees.

Every frame surfaces.update() sends each plane's projective matrix to updateElementGeometry(), so the browser hit tests the button on a tilted cutout where it is drawn. A cutout that faces away from the camera, which is every cutout when the book is closed, is parked off the canvas so it cannot be clicked through the page. Clicking a button changes its element, the paint event reports it, and only that cutout's texture is uploaded again.

The animation loop runs only while the open angle is moving, and each move is timed by the clock rather than by frames, so a slow phone finishes the opening fold in 1.1 seconds like a fast one. Once the book settles nothing is drawn until something changes.

Live checks

These checks wait for a tap because they read pixels from the WebGL canvas. They drive the visible book: they scroll it into view, move the open angle, press buttons and open the disclosure, then put everything back.

Findings