webdevpuneet.com

Three.js Scroll Möbius Ride — Neon Glider on a Twisted Track

Three.js Scroll Möbius Strip Ride · Scroll · Plain HTML, CSS & JS · Live preview

About this UI Snippet

How to Build a Scroll-Driven Möbius Strip Ride With Three.js and GSAP

Screenshot of the Three.js Scroll Möbius Strip Ride snippet rendered live

The Three.js Scroll Möbius Strip Ride snippet puts the camera on the centerline of a mathematically real Möbius strip and lets scroll drive it around — with the twist that makes the topology famous: after one full ring lap the camera is riding the *underside* of the surface, upside down relative to where it started, and only after a second lap (u = 4π) does it come home. GSAP's ScrollTrigger scrubs the ride parameter; the geometry, the roll, and the two-lap structure all fall out of the parametrization.

Building the strip from its equation

The surface is generated directly from the Möbius parametrization: for ring angle u and width coordinate v, the point is ((R + vW·cos(u/2))·cos u, vW·sin(u/2), (R + vW·cos(u/2))·sin u). The u/2 half-angle is the entire secret — the strip's cross-section rotates half a turn while u makes a full turn, joining the ribbon to itself with a flip. A 320×12 grid of these points becomes an indexed BufferGeometry with uv coordinates, a per-vertex color that drifts cyan to violet to pink around the ring, and computeVertexNormals(). It is rendered DoubleSide because a one-sided surface, ironically, needs both GL faces drawn. A canvas-drawn track texture (glowing edge rails, lane lines, a dashed cyan center line) is tiled 72 times along the strip and reused as the emissive map, so the lines glow even when the rider is upside down and the key light is behind the ribbon.

A camera frame with no world up

Riding a surface that turns you upside down means camera.lookAt with the default world-up would fight the roll and flip violently at the poles of the twist. Instead the snippet constructs the rider's frame from the surface itself: two finite-difference tangents (one step along u, one along v) cross-multiplied into a local surface normal. A small frameAt(u) helper returns that point and normal for any u in [0, 4π), and three things use it: the chase camera sits 1.5 units above the centerline with camera.up set to the normal, a glowing arrowhead glider hovers a little further ahead with its own up and lookAt from the same frame, and the look-at target sits further down the track. The camera therefore rolls exactly as the surface rolls — by the end of lap one it is fully inverted, and the HUD's ROLL readout (the angle between the normal and world up) reads 180°.

The 4π edge and the lap-two flip

Two details encode the topology honestly. The neon boundary is a single TubeGeometry (plus a wider additive halo) along a closed curve built by walking u from 0 to 4π at v = 1 — because point(u + 2π, v) = point(u, −v), that one walk visits both sides of the ribbon and closes only after two circuits, exactly like the strip's single edge. And during lap two, the finite-difference normal (which always samples the same parametric side) is negated so the ride surface stays underfoot; without the flip the camera would clip through the strip the moment u crossed 2π. These are the kinds of sign subtleties that make one-sided surfaces a rite of passage.

Speed made visible

A camera gliding over a smooth ribbon has no motion cues, so the scene layers several. The tiled center dashes and cross lines stream past underfoot. Twenty neon rings are threaded onto the strip like gates, each one brightening as the glider approaches — opacity derived from angular distance with proper 2π wrapping — much like the recycled particles of the scroll tunnel. Soft dust drifts around the ring (kept out of the tube the camera flies through), and fog-free stars sit far behind. The edge halo and the glider's underglow pulse on clock time so the scene idles alive, and story captions change at key moments of the ride.

Why scrub suits this topology

The Möbius property is an experiential claim — "go around once and you are flipped" — that a fired animation asserts but a scrub *proves*: users can stop at u = 2π, look around while inverted, and back up to re-watch the roll accumulate. The gear train scrubs an angle and the pendulum wave scrubs time; this scrubs a coordinate on a surface, completing the series' tour of what a single scrubbed number can be. For the straight-line cousin of this ride, see the staircase climb.

What's included

Features

True Möbius parametrization — the u/2 half-angle term builds the one-sided surface from its equation
Neon track: canvas texture used as map and emissive map, with cyan-to-pink vertex colors around the ring
Chase camera and glowing glider share one frameAt(u) helper — camera.up follows the surface normal, no world up
The ride rolls fully inverted at one lap and recovers at two, with a live ROLL readout to prove it
Single edge drawn as one closed neon tube over 4π, plus an additive halo that pulses on clock time
Twenty gate rings threaded on the ribbon light up as the glider approaches
Story captions, lap counter and a progress bar with a halfway mark in a glass HUD
Round-sprite dust and fog-free stars for depth; wider FOV and top HUD on narrow screens

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 on a title card over a neon track: a glowing glider ahead, the single edge rail on both sides, and gates threaded on the ribbon.
  3. 3
    Scroll to rideThe chase camera follows the glider and rolls with the surface. The HUD shows lap, roll angle, and progress while captions narrate the twist.
  4. 4
    Pause at 50%At one full ring lap the ROLL readout says 180° — you are upside down, yet still on the same side of the strip.
  5. 5
    Complete lap twoOnly at 100% (u = 4π) does the camera return to its starting orientation — the Möbius property, proven by scroll.
  6. 6
    Reshape the ribbonChange R and W for ring radius and strip width, or replace u/2 with 3u/2 in mobiusPoint for a three-half-twist strip — the frame math adapts unchanged.

Real-world uses

Common Use Cases

Math education and topology pages
The strongest possible demo of one-sidedness: students ride the flip, pause inverted, and reverse it — pair with a pendulum wave for a physics-and-math duo.
Infinity-themed brand loops
Logistics, recycling, and subscription brands get a literal endless-loop hero where the journey visibly never hits an edge.
Award-site signature interactions
A camera that rolls upside down mid-scroll is a memorable centerpiece, more disorienting than a scroll tunnel flythrough.
Album, film, and title sequences
Use the inversion moment as a narrative beat — drop a title card exactly at u = 2π when the world is upside down.
Puzzle and perspective game promos
Monument-Valley-adjacent games can let visitors experience impossible geometry before seeing gameplay.
Generative and kinetic art portfolios
Present the strip as sculpture with the ride as the exhibition path, alongside pieces like the wave ribbon.

Got questions?

Frequently Asked Questions

That is the defining property of a Möbius strip. The u/2 term rotates the strip's cross-section half a turn per ring lap, so after u = 2π the rider is on the same surface but locally inverted — the "other side" that does not exist as a separate side. Only after 4π of travel has the accumulated roll returned to identity. The scrub lets users verify this by pausing at 50% and looking around while upside down.

lookAt orthonormalizes against camera.up; with a fixed world up, the computed right vector degenerates as the surface rolls past 90° and the camera snaps or spins wildly. Setting camera.up to the local surface normal each frame — computed from cross(tangent-along-u, tangent-along-v) — lets the camera roll smoothly and continuously through full inversion, which is the entire point of the ride.

The finite-difference normal always samples the same parametric v-direction, but after u = 2π the rider is physically on the opposite face of the ribbon, where that sampled normal points into the surface. Negating it during lap two keeps the camera hovering 1.5 units above the face underfoot instead of clipping through the strip at the seam. It is a one-line fix for a sign error that is invisible until it teleports the camera.

A Möbius strip has exactly one edge: follow the v = +1 border around the ring and you arrive at v = −1 of your starting point, needing a second lap to close the loop. Because point(u + 2π, v) equals point(u, −v), walking u through 4π at v = 1 traces that whole loop, which becomes one closed neon tube. Drawing two separate v = ±1 circles would render the topology of a cylinder — visibly wrong once you know what to look for.

Yes. Export via the JSX, Vue, Angular, or Tailwind buttons. Build the geometry, gates, glider, and ScrollTrigger in a mount effect against a canvas ref, keeping the scratch vectors as effect-scope consts. On cleanup kill the ScrollTrigger, dispose every geometry, material and canvas texture, and call renderer.dispose(). The ride value lives in a plain object — never React state.

Copy & paste

Source Code

<section class="mob-stage" id="mobStage">
  <canvas id="mobCanvas"></canvas>
  <div class="mob-vignette"></div>
  <div class="mob-intro" id="mobIntro">
    <p class="mob-kicker">One surface · one edge</p>
    <h2>The Möbius Ride</h2>
    <p class="mob-hint">Scroll to ride <span class="mob-mouse"><i></i></span></p>
  </div>
  <p class="mob-caption" id="mobCaption"></p>
  <div class="mob-hud">
    <div class="mob-hud-row">
      <span>LAP <b id="mobLapNo">1</b>/2</span>
      <span>ROLL <b id="mobRoll">0</b>°</span>
      <span><b id="mobLap">0</b>%</span>
    </div>
    <div class="mob-bar"><i id="mobBar"></i><em></em></div>
  </div>
</section>
<section class="mob-bottom">
  <p class="mob-kicker">Back where you started</p>
  <h2>Two laps. One side. No edge you can fall off.</h2>
</section>

Extend with AI

Take This Snippet Further With AI

You do not need to fight quaternion flips and sign errors alone — this snippet already contains the two subtle fixes (surface-normal camera.up and the lap-two negation) that make riding a one-sided surface work. Paste its HTML, CSS, and JS into an AI assistant like Claude and ask it to explain the u/2 half-twist term, why the boundary edge needs 4π to close, or what breaks with a world-up lookAt. The same assistant can extend the ride — a trefoil-knot track using the same frameAt technique, a fading light trail behind the glider, a small orbit-view minimap that shows where the rider is on the ring, or three half-twists (3u/2) to compare topologies. 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 Möbius strip ride" in plain HTML, CSS, and JavaScript using Three.js and GSAP's ScrollTrigger plugin, all loaded from a CDN (no bundler, no build step).

Requirements:
- A pinned full-viewport section with a transparent WebGLRenderer over a dark purple radial-gradient background, a vignette, PerspectiveCamera (72° FOV, 85° when the aspect is below 0.8), FogExp2, hemisphere + directional light, and a pink point light that follows the glider.
- A mobiusPoint(u, v, target) function with ring radius R ≈ 14 and half-width W ≈ 3.2: r = R + vW·cos(u/2); position = (r·cos u, vW·sin(u/2), r·sin u).
- The strip as an indexed BufferGeometry: a 320×12 grid over u ∈ [0, 2π], v ∈ [−1, 1], with uv (u tiled 72 times), a per-vertex color drifting cyan → violet → pink, computeVertexNormals(), and a MeshStandardMaterial (side: DoubleSide, vertexColors) whose map AND emissiveMap are one canvas texture: dark deck, pink edge rails, faint lane and cross lines, a cyan center dash.
- The single edge as one closed CatmullRomCurve3 built by walking u from 0 to 4π at v = 1.02, drawn as a thin bright TubeGeometry plus a wider additive halo tube whose opacity pulses with time.
- A frameAt(u, P, N) helper for u in [0, 4π): P = centerline point, N = normalize(cross(finite-difference tangent along u, tangent along v)), negated when u ≥ 2π so the surface stays underfoot across the seam. Never use a world up vector.
- Twenty additive TorusGeometry gates (radius ≈ 0.92W, alternating cyan and pink) placed with frameAt, facing along the track; each brightens as the glider nears it (2π-wrapped distance ahead).
- A glider: a 4-sided cone flattened and turned to point along +Z, with an additive soft glow plane underneath, placed 0.13 rad ahead of the camera and 0.3 above the surface with a small bob, oriented with up = N and lookAt further down the track.
- Dust: ~1400 additive round-sprite points around the ring, excluding a tube of radius W + 1.5 around the centerline; ~1600 fog-free stars on a far sphere. Make the round sprite from a radial-gradient canvas.
- One GSAP tween (ease "none") scrubbing u from 0 to 4π (TWO ring laps) on a ScrollTrigger with pin: true, scrub 1, end +=600%.
- Each frame: camera at P + 1.5N with camera.up = N, looking at the frame point 0.36 rad ahead lifted 0.2.
- UI: an intro title card ("The Möbius Ride", gradient text, animated scroll-mouse hint) that hides after 1%; story captions that cross-fade at set progress points; a glass HUD (bottom-left, top on mobile) with LAP 1/2, ROLL ° (acos of N.y), percent, and a gradient progress bar with a halfway tick; a closing section below.
- Confirm: at 50% ROLL reads ~180°; at 100% it is back near 0°; reverse scrolling unwinds the roll smoothly.

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.