smoke
A heading condenses out of drifting volumetric smoke as it comes into view, or dissolves into it as it leaves.
Islay · Distillery tours
Peat, smoke and sea air
Walk the malting floor, stand by the kiln while the peat burns, and taste a ten-year cask straight from the warehouse. Daily at eleven and three.
Live preview needs WebGPU or WebGL 2. A distillery tour headline on a dark page that condenses out of drifting, backlit smoke, with a kicker and a short paragraph under it.
This example failed to draw.
Leaving the page dissolves the heading into smoke; entering condenses it.
Usage
Put it on a large heading or a short line of display text. Not img, video, canvas, svg or form fields. Text with text-shadow, a text stroke, background-clip: text or vertical writing stays as it is. start() registers smoke, 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 smoke<div class="sm-hero"> <p class="sm-kicker">Islay · Distillery tours</p> <h2 class="sm-headline" data-dio="smoke" >Peat, smoke and sea air</h2> <p class="sm-lede">Walk the malting floor, stand by the kiln while the peat burns, and taste a ten-year cask straight from the warehouse. Daily at eleven and three.</p></div>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.sm-headline', 'smoke', { style: 'smoke', trigger: 'view', density: 1, speed: 1, rise: 1, turbulence: 1, duration: 2.4,})import { start } from '@dioramajs/diorama'import smoke from '@dioramajs/text/smoke'
const app = start()app.attach('.sm-headline', smoke({ style: 'smoke', trigger: 'view', density: 1, speed: 1, rise: 1, turbulence: 1, duration: 2.4,}))Page transitions
Leaving a page, the heading dissolves up into smoke; entering, it condenses out of it. 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 | 'smoke' | 'mist' | 'ink' | 'smoke' |
|
triggerrebuildsdata-dio-trigger | 'view' | 'scroll' | 'hover' | 'loop' | 'view' |
|
densitydata-dio-density | number0 to 3 | 1 | Thickness of the smoke; 0 leaves only the letters softening and fading. |
speeddata-dio-speed | number0 to 3 | 1 | Pace of the swirling and drifting; 0 freezes the smoke in place. |
risedata-dio-rise | number0 to 3 | 1 | How far the smoke drifts upward as it leaves the letters; 0 keeps it in place. |
turbulencedata-dio-turbulence | number0 to 3 | 1 | Strength of the swirls; 0 lets the smoke drift without curling. |
durationdata-dio-duration | number0.5 to 8 s | 2.4 | Time the view trigger takes to condense, and a hover wisp takes to settle. |
colorrebuildsdata-dio-color | string | '' | Any CSS color for the smoke; empty uses grey-white for smoke, a pale fog for mist or the text color for ink. |
seeddata-dio-seed | number1 to 100 | 1 | Picks the pattern of the swirls; the same seed drifts the same way. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads delta, presence, size, x and y
. Draws at a steady rate while it is on screen and stops when it leaves. While the view trigger condenses, while scrolling with the scroll trigger and while hover wisps settle; none at rest. The loop trigger draws 30 frames a second while it is on screen. How a frame is decided.
Reduced motion and touch
With reduced motion it is off and the element shows as plain HTML. Off: the text shows as it is, without smoke.
Runs on every device. The same as with a mouse; with the hover trigger a tap breathes a wisp off the letters.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { smoke: { reducedMotion: 'static' } } })Cost and quality
- Download
- 13.6 KB min+gzip the first time a page uses it
- GPU
- One quad over the text and the room its smoke needs, marching 16 steps through the volume per pixel at the high tier, each with up to eight texture reads; empty air costs three.
- Memory
- A canvas of the text at twice its CSS size, a coarse half-float field of the glyphs and a 32 by 32 by 32 noise cube shared by every heading: about 3 MB for a large heading.
- Frames
- Draws while on screen
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | 8 steps through the volume without a light step, and the text rastered at 1 device pixel per CSS pixel. |
medium | 12 steps with one step toward the light. |
Recipes
Fog that lifts as the visitor scrolls
data-dio-trigger="scroll" ties the smoke to the heading’s place in the window: it condenses as the heading rises toward the middle, stays plain text around the middle, and dissolves upward as it leaves the top. Scrolling back runs it in reverse. A heading on the first screen starts as text and only dissolves once the page scrolls. mist is a pale fog for light pages, mixed from the page color and the text color.
<h2 data-dio="smoke" data-dio-style="mist" data-dio-trigger="scroll">Morning on the lake</h2>Ink blooming in water
ink takes the text color and lets it billow out in dark plumes that curl more and rise less, the way ink spreads in a glass of water. A higher turbulence curls it further.
<h2 data-dio="smoke" data-dio-style="ink" data-dio-turbulence="1.6" style="color: #1c3f8a">Written in water</h2>A heading that keeps smoldering
data-dio-trigger="loop" keeps the letters crisp while thin plumes rise off a few of them at a time, at 30 frames a second while the heading is on screen and none off screen. speed="0" freezes the smoke, and rise sets how high it climbs.
<h2 data-dio="smoke" data-dio-trigger="loop" data-dio-rise="1.4">Slow burn</h2>Notes
The smoke is a volume, not a flat picture: each pixel marches a short ray through it, front to back, from a little in front of the page to a little behind it. Its shape comes from a coarse field of the glyphs (their distance, two blurs and a plume that streams up off their tops), swirled by a tiling 3D noise and carried upward over time. Light comes from behind and above: each step looks once or twice toward the light for the smoke in the way, so thin wisps glow at their edges and the thick parts fall into their own shadow. The letters themselves sit in the middle of the volume, so smoke in front of them veils them and smoke behind them does not. Because the ray goes through the page camera, the layers of smoke shift against each other as the heading moves through the window.
At rest the heading is plain DOM text: the view trigger draws only while it condenses, the scroll trigger only while scrolling and the hover trigger only while wisps settle. Under reduced motion the text shows as it is, without smoke. Text with text-shadow, -webkit-text-stroke, background-clip: text or a vertical writing mode stays as it is, with a warning in development. style, trigger and color rebuild the effect when they change.