tunnel
The phrases of a pinned section stand one behind another in real depth, and the scroll flies the camera through them.
Every launch starts in the dark.
A sketch on a napkin.
A thousand late nights.
One stubborn idea.
Now it ships.
Live preview needs WebGPU or WebGL 2. A product launch story in five lines that wait one behind another down a dark corridor, flown through as you scroll.
This example failed to draw.
Usage
Put it on a block inside a pinned section, usually filling its sticky stage, whose children are the phrases, one element each, such as paragraphs. Not img, video, canvas, svg or form fields. start() registers tunnel, so the attribute alone puts it on an element. The tabs below are the example above, with the values you set.
To change its code, copy the source into your effects folder; the copy replaces the built-in.
npx @dioramajs/diorama add tunnel<div class="tn-scene"> <div class="tn-story" data-dio="tunnel"> <p>Every launch starts in the dark.</p> <p>A sketch on a napkin.</p> <p>A thousand late nights.</p> <p>One stubborn idea.</p> <p>Now it ships.</p> </div></div>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.tn-story', 'tunnel', { style: 'tunnel', depth: 1, perspective: 1, fade: 0.6, blur: 10, streak: 1, twist: 50, lines: true, color: 'currentColor',})import { start } from '@dioramajs/diorama'import tunnel from '@dioramajs/text/tunnel'
const app = start()app.attach('.tn-story', tunnel({ style: 'tunnel', depth: 1, perspective: 1, fade: 0.6, blur: 10, streak: 1, twist: 50, lines: true, color: 'currentColor',}))Markup it reads
:scope > *inside: Each child element with text is one phrase, in reading order; the last one stays as text at the end.
Page transitions
The phrases fade with the copy as the page leaves or enters. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
stylerebuildsdata-dio-style | 'tunnel' | 'zoom' | 'spiral' | 'tunnel' |
|
depthdata-dio-depth | number0.3 to 3 | 1 | Distance between two phrases, in heights of the element. |
perspectivedata-dio-perspective | number0.3 to 3 | 1 | Strength of the perspective: higher puts the eye closer, so phrases grow faster. |
fadedata-dio-fade | number0 to 2 | 0.6 | Fog toward the distance; 0 shows every phrase behind at full strength. |
blurdata-dio-blur | number0 to 40 px | 10 | Blur of a phrase as it passes the viewer, at its nearest; 0 keeps it sharp.At most low 0 by quality tier. |
streakdata-dio-streak | number0 to 3 | 1 | Motion streaks with the scroll speed, toward the edges; 0 turns them off.At most low 0 by quality tier. |
twistdata-dio-twist | number-180 to 180° | 50 | Turn of the helix from one phrase to the next, with style spiral. |
linesdata-dio-lines | boolean | true | Draws the guide lines of the tunnel or the helix; zoom has none. |
colordata-dio-color | color | 'currentColor' | Color of the phrases and lines; currentColor keeps the text color. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads height, size, velocity, width, x and y
. Draws only when you scroll, move the pointer over it or change a param. Only while the page scrolls, and a few more while the scroll speed settles with streaks on; none at rest. How a frame is decided.
Reduced motion and touch
With reduced motion it is off and the element shows as plain HTML. The effect does not run: the phrases stay as the page lays them out, one under another.
Runs on every device. The same as with a mouse: the scroll drives it.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { tunnel: { reducedMotion: 'static' } } })Cost and quality
- Download
- 10.8 KB min+gzip the first time a page uses it
- GPU
- One instanced draw of up to seven phrase cards with a 12-tap blur, and one draw of a few hundred thin line quads.
- Memory
- One atlas of every phrase at twice its CSS size, at most 4096 px a side.
- Frames
- Idle at rest
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | The phrases are rastered at 1 device pixel per CSS pixel instead of 2, without blur or streaks. |
Recipes
A launch story told on a pinned section
Give the section one screen of height per phrase: five phrases take 500vh, so the stage stays pinned for four screens of scroll and each phrase gets a screen to arrive, hold and pass. Put the effect on a block that fills the sticky stage, with the phrases as its children, and keep the background on the stage: while it draws, the effect’s own element is hidden, background included.
<section class="launch" data-dio-section style="height: 500vh"> <div class="stage" style="position: sticky; top: 0; height: 100vh; background: #08090d" > <div class="story" data-dio="tunnel" style="height: 100%" > <p>Every launch starts in the dark.</p> <p>A sketch on a napkin.</p> <p>A thousand late nights.</p> <p>One stubborn idea.</p> <p>Now it ships.</p> </div> </div></section>Lay the phrases out as a plain list, one under another, centered in the stage. That is what visitors see under reduced motion and without WebGL, and what screen readers and search read in every case. With the effect running they stack in one spot: the camera slows down on each phrase so it can be read, and at the end of the section the last one stays as plain text.
A calm zoom for a hotel or wellness intro
style="zoom" drops the corridor and flies straight through the phrases, each centered behind the one before. A light, thin typeface and a bigger blur make the passing line melt away before the next one settles.
Slow down.
Breathe in.
Look closer.
Stay a while.
Live preview needs WebGPU or WebGL 2. Four short lines on warm paper, Slow down, Breathe in, Look closer, Stay a while, flown through one after another as you scroll.
This example failed to draw.
<div class="tz-scene"> <div class="tz-story" data-dio="tunnel" data-dio-style="zoom" data-dio-blur="16" > <p>Slow down.</p> <p>Breathe in.</p> <p>Look closer.</p> <p>Stay a while.</p> </div></div>Event details on a spiral
style="spiral" strings the phrases along a helix that turns as the camera travels, so each line swings round the axis and rights itself as it arrives. twist sets how far the helix turns from one phrase to the next. Short phrases, such as a date, a time and a place, read best this way.
<div class="details" data-dio="tunnel" data-dio-style="spiral" data-dio-twist="70"> <p>Friday</p> <p>23:00</p> <p>Warehouse 9</p> <p>Bring friends</p></div>Notes
The phrases are flat cards in real depth, seen through a camera an element’s height in front of them, divided by perspective. They take their colors from the text, one color per phrase if the page sets them, and the guide lines take the element’s color; color paints both. Under reduced motion the effect does not run at all.
A fast scroll streaks the letters away from the middle, the way the camera’s speed would blur them. The streaks fade with the scroll speed, and the page draws no frames at rest.
Without a pinned section around it, the scroll through the viewport drives the camera: it starts as the element’s middle passes 85% of the viewport height and reaches the last phrase at 25%.
The canvas cannot draw background-clip: text, text-shadow, -webkit-text-stroke or vertical writing modes the way the browser does; such phrases stay as they are, with a warning in development.
style rebuilds the effect; depth, perspective, fade, blur, streak, twist, lines and color change live.