webdevpuneet.com

Three.js Scroll Spiral Staircase Climb — Tower Ascent

Three.js Scroll Spiral Staircase Climb · Scroll · Plain HTML, CSS & JS · Live preview

About this UI Snippet

How to Build a Scroll-Driven Spiral Staircase Climb With Three.js and GSAP

Screenshot of the Three.js Scroll Spiral Staircase Climb snippet rendered live

The Three.js Scroll Spiral Staircase Climb snippet walks the visitor up an open-well spiral stair inside an old brick tower, one tread per scroll notch. At the top it leans over the brass rail and looks straight down the well at a glowing compass floor 38 metres below. GSAP's ScrollTrigger scrubs one 0–1 value. The step index, camera position, footstep bob, captions, HUD and the final look-down are all derived from it each frame.

One helix drives the whole tower

Tread i sits at angle i × ANGLE_STEP (24 treads per turn) and height i × RISE. The treads, light strips, balusters, handrail, window and sconce positions, and the camera all use that same mapping. Retune ANGLE_STEP, RISE or the radii and everything stays aligned: the camera always walks the middle of the treads and the rail always follows the well edge.

Wedge treads, instanced

Each tread is an annular-sector Shape (inner arc at the well, outer arc at the wall), extruded with a small bevel and rotated flat. It is drawn with one InstancedMesh of 168 copies, each rotated to its angle, so the whole stair is one draw call. A thin amber strip under every nose and a brass baluster on the well side are two more instanced meshes. The handrail is one TubeGeometry along a custom THREE.Curve that returns helix points, so it is a single smooth spiral with no seams.

A tower that feels lit

All textures are drawn on canvases at load: brick for the wall, speckled stone for the treads, arched night-sky windows with mullions, and a gold compass-rose floor. Windows and warm sconces alternate up the wall as sprites with additive glow. Two point lights move with the visitor, a flickering lantern at the camera and a second one a few steps ahead, so the treads light up as you reach them. A cool hemisphere fill and exponential fog make the stair fade into darkness above and below. A skylight at the top drops a soft shaft of light down the well, and dust drifts in it.

Footsteps tied to scroll, not time

The camera's bob is |sin(stepIndex × π)|: one dip per tread. Because it comes from the scrubbed step index rather than the clock, stopping scroll stops the footsteps and scrolling back walks you down. Only ambient things such as the lantern flicker, dust drift and shaft shimmer run on clock time.

The look-down finale

The climb uses the first 86% of the scroll. In the last 14% the camera slides inward past the rail until it hangs over the open well. Its view direction blends from "ahead and up the spiral" to straight down, and camera.up blends from world Y to the outward radial so the turn never flips. The spiral of treads and rail then recedes into the fog toward the compass floor, which ignores fog so it glows at the bottom. While looking down the light shaft and lantern fade, because seen end-on they would wash out the view. For other single-curve camera rigs, see the scroll tunnel and the scroll camera path.

What's included

Features

One helix mapping places treads, strips, balusters, handrail, windows, sconces and the camera
168 bevelled wedge treads in a single InstancedMesh, with instanced amber nose strips and balusters
Smooth brass handrail as one TubeGeometry along a custom helix Curve
Canvas-drawn brick, stone, arched-window and compass-floor textures — no downloads
Lantern and look-ahead point lights that travel with the visitor, plus fog and a hemisphere fill
Skylight light shaft with drifting dust, moonlit windows and glowing wall sconces
Footstep bob tied to the scrubbed step index, so steps stop when scrolling stops
Finale that leans over the rail and looks straight down the well, with a level camera.up blend

Step by step

How to Use

  1. 1
    Load the three CDN scriptsAdd three.min.js, gsap.min.js, and ScrollTrigger.min.js in that order before the snippet JS.
  2. 2
    Paste HTML, CSS, and JSA pinned view opens at the foot of the tower with the "168 Steps to the Light" title card over the first treads.
  3. 3
    Scroll to climbEach scroll notch is a step. The camera bobs once per tread, the lantern lights the stone ahead, and the HUD counts steps and metres.
  4. 4
    Read the captionsShort lines fade in at set heights — moonlit windows, the warm brass rail, the draught from the skylight.
  5. 5
    Look down at the topOn the landing the camera leans over the rail and turns straight down the spiral well to the glowing compass floor.
  6. 6
    Reshape the towerChange STEPS, ANGLE_STEP, RISE, R_IN and R_OUT for a taller, tighter or wider stair — treads, rail and camera follow automatically.

Real-world uses

Common Use Cases

Architecture and interiors portfolios
Showcase a stairwell, atrium, or lobby design by literally walking the visitor up it as they scroll through project details.
Narrative "ascent" storytelling
Swap the captions for milestones, chapters, or a company timeline and let the climb carry the story, much like the ring markers in the scroll tunnel.
Game and level-design showcases
Demonstrate a vertical level, a wizard tower or a dungeon descent with a first-person climb instead of static screenshots.
Teaching parametric camera rigs
A compact example of instancing, a custom Curve, and a camera that blends both its view direction and its up vector, alongside the scroll camera path.
Product reveal build-ups
Use the climb as a slow-burn intro and put your product or headline on the landing, where the look-down gives a dramatic reveal.
Mystery and suspense pages
The fog, lantern flicker and vertigo finale suit mystery novels, escape rooms and puzzle-game marketing pages.

Got questions?

Frequently Asked Questions

Each tread is the same wedge geometry: an annular-sector Shape extruded and laid flat. One InstancedMesh holds all 168 copies, and each instance matrix sets the height and rotates it to its angle on the helix. The nose strips and balusters are two more InstancedMeshes, so the whole stair is a handful of draw calls.

The bob is |sin(stepIndex × π)|, so the camera dips once per tread. Because it is derived from the scrubbed value, it stops the moment scrolling stops and plays backwards when scrolling up. A time-based bob would keep "walking" while the visitor stands still, which feels wrong.

lookAt needs an up vector that is not parallel to the view direction. As the view direction blends toward straight down, camera.up blends from world Y to the horizontal outward direction at the camera, so the two never line up and the turn stays smooth in both scroll directions.

The shaft is an additive cylinder. Seen from the side it is a faint glow, but looking down its length the layers add up to a white-out. The lantern also sits right above the landing. Fading both with the look-down progress keeps the spiral readable.

Yes. Use the JSX, Vue or Angular export. Build the scene in a mount effect against a canvas ref. On cleanup kill the ScrollTrigger, dispose the instanced and tube geometries, materials and canvas textures, and call renderer.dispose() so the pin and WebGL context are released.

Copy & paste

Source Code

<section class="stc-stage" id="stcStage">
  <canvas id="stcCanvas"></canvas>
  <div class="stc-vignette"></div>
  <div class="stc-intro" id="stcIntro">
    <p class="stc-kicker">The old library tower</p>
    <h2>168 Steps to the Light</h2>
    <p class="stc-hint">Scroll to climb <span class="stc-mouse"><i></i></span></p>
  </div>
  <p class="stc-caption" id="stcCaption"></p>
  <div class="stc-hud">
    <div class="stc-hud-row">
      <span>STEP <b id="stcFloor">1</b> / <b id="stcFloorMax">168</b></span>
      <span><b id="stcHeight">0.0</b> m</span>
    </div>
    <div class="stc-bar"><i id="stcBar"></i></div>
  </div>
</section>
<section class="stc-bottom">
  <p class="stc-kicker">Top of the tower</p>
  <h2>Worth every step. Don't look down… too long.</h2>
</section>

Extend with AI

Take This Snippet Further With AI

You do not need to work out instanced wedge treads, a helix handrail, or a camera that turns from climbing to looking straight down — this snippet already does all of it. Paste its HTML, CSS, and JS into an AI assistant like Claude and ask it to explain the instance matrices, the custom Curve behind the handrail, or why camera.up has to blend during the look-down. The same assistant can extend it: a bookshelf wall for a real library tower, doors on landings every full turn that open as you pass, footstep sounds synced to the step index, or a reverse "descent into the dungeon" version. Treat the code as a starting point to interrogate and reshape, not a finished artifact.

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 spiral staircase climb" in plain HTML, CSS, and JavaScript using Three.js (r128) and GSAP's ScrollTrigger, all from a CDN (no bundler, no build step).

Requirements:
- A pinned full-viewport section with a WebGLRenderer, warm-dark background and FogExp2, a PerspectiveCamera (68° FOV, 82° when the aspect is below 0.8), and a vignette overlay.
- One helix mapping: tread i at angle i × (2π/24) and height i × 0.23, 168 treads, open well radius 3.3, outer tread edge 6.9, brick wall at radius 7.
- Canvas textures drawn at load: brick (wall, BackSide open cylinder), speckled stone (treads), arched night-sky window with mullions, a gold compass-rose floor (emissive, fog: false).
- Treads: an annular-sector Shape extruded 0.16 with a small bevel, laid flat, in one InstancedMesh of 168 rotated copies. An instanced amber MeshBasic strip under each tread nose and an instanced brass baluster at the well edge.
- Handrail: one TubeGeometry along a custom THREE.Curve returning helix points 1.0 above the well edge. A stone top landing with a round brass rail; a dark ceiling ring with a bright skylight disc and glow at the top.
- Windows and warm sconces alternating every 8 steps on the wall, each with an additive glow sprite. A faint additive light-shaft cylinder down the well (vertical gradient map) and ~900 drifting dust points.
- Lights: hemisphere fill, a weak cool top light, a flickering lantern point light at the camera and a second point light a few steps ahead.
- One GSAP tween (ease "none") scrubbing p 0→1 (pin, scrub 1, end +=600%). For p < 0.86 the step index goes from 1 to the landing; the camera walks radius 5.2 at eye height 1.65 with a bob of |sin(step × π)| × 0.07, looking about 4.5 steps ahead and up.
- From 0.86 to 1: the camera slides inward past the rail over the well, its view direction blends to straight down, and camera.up blends from world Y to the outward radial. Fade the shaft and lantern during this so the view does not wash out.
- UI: intro title card ("168 Steps to the Light"), italic serif captions that cross-fade at set progress points (ending "Now… look down."), and a glass HUD with step n / 168, height in metres and a progress bar; HUD on top for mobile.
- Scrolling back must walk back down exactly.

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.