clouds
A sky of soft layered clouds for the time of day, daylight, a sunset or a moonlit night, drifting in the wind and parting on scroll.
Direct flight, 2 h 55 min
Lisbon for the weekend
- Departs
- Fri 18:40
- Returns
- Sun 21:15
- From
- €89
Cabin bag included. Seats by the window go first, so pick yours early.
Live preview needs WebGPU or WebGL 2. A flight card with a blue daytime sky of soft drifting clouds beside the route, times and price.
This example failed to draw.
Usage
Put it on an empty decorative element behind the content, such as an aria-hidden div filling a hero; its CSS background is the look without WebGL. start() registers clouds, 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 clouds<article class="cl-trip"> <div class="cl-sky" aria-hidden="true" data-dio="clouds" data-dio-cover="0.45" ></div> <div class="cl-info"> <p class="cl-kicker">Direct flight, 2 h 55 min</p> <h2>Lisbon for the weekend</h2> <dl> <div><dt>Departs</dt><dd>Fri 18:40</dd></div> <div><dt>Returns</dt><dd>Sun 21:15</dd></div> <div><dt>From</dt><dd>€89</dd></div> </dl> <p>Cabin bag included. Seats by the window go first, so pick yours early.</p> </div></article>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.cl-sky', 'clouds', { style: 'day', cover: 0.45, speed: 0.2, scale: 1, sun: 0.6, depth: 0.2, scroll: 0.3, fps: 30,})import { start } from '@dioramajs/diorama'import clouds from '@dioramajs/backgrounds/clouds'
const app = start()app.attach('.cl-sky', clouds({ style: 'day', cover: 0.45, speed: 0.2, scale: 1, sun: 0.6, depth: 0.2, scroll: 0.3, fps: 30,}))Page transitions
Fades with the page transition. 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 | 'day' | 'sunset' | 'night' | 'day' |
|
coverdata-dio-cover | number0 to 1 | 0.5 | How much of the sky the clouds cover; 0 a clear sky, 1 overcast. |
speeddata-dio-speed | number0 to 1 | 0.2 | Wind speed; 0 holds the clouds in place. |
scaledata-dio-scale | number0.3 to 3 | 1 | Size of the clouds. |
sundata-dio-sun | number0 to 1 | 0.6 | Brightness of the sun or the moon, its glow and the light on cloud edges; 0 hides it. |
depthdata-dio-depth | number0 to 1 | 0.2 | How far the layers shift apart with the pointer; 0 ignores the pointer. |
scrolldata-dio-scroll | number0 to 1 | 0.3 | How far the layers move while the element crosses the viewport, nearer ones more; 0 keeps them. |
layersrebuildsdata-dio-layers | number1 to 3 | 3 | Layers of clouds, 1 to 3.At most low 1, medium 2 by quality tier. |
fpsdata-dio-fps | number0 to 60 | 30 | Most frames a second the wind draws; 0 holds it still.At most low 15, medium 24 by quality tier. |
seedrebuildsdata-dio-seed | number1 to 100 | 1 | Shapes of the clouds. |
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, hover, pointer, progress, reducedMotion and size
. Draws at a steady rate while it is on screen and stops when it leaves. Up to fps frames a second while on screen, none off screen or at fps 0; pointer and scroll draw at full rate. How a frame is decided.
Reduced motion and touch
With reduced motion it shows a still frame: motion inputs are zero and time stands still. A still sky: no wind, and neither the pointer nor scroll moves the clouds.
Runs on every device. The layers shift with a finger while it is on the screen; scrolling works as usual.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { clouds: { reducedMotion: 'off' } } })Cost and quality
- Download
- 2.1 KB min+gzip the first time a page uses it
- GPU
- One pass over the element: four reads of a noise tile per layer and pixel.
- Memory
- A 256 × 256 noise tile, 256 KB, shared by every clouds of the same seed.
- 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 | At most 15 frames a second and one layer of clouds. |
medium | At most 24 frames a second and two layers. |
Recipes
A travel hero
Put the clouds on an empty aria-hidden element that fills the hero and start the app with canvas: 'behind', so the heading sits over the sky. The element’s CSS background is what visitors see before the engine draws and without WebGL: a gradient in the colors of the style.
<header class="hero"> <div class="hero-sky" aria-hidden="true" data-dio="clouds" data-dio-cover="0.4" ></div> <h1>Fly to Lisbon from €49</h1> <a class="cta" href="/flights">Find a flight</a></header>.hero { position: relative; isolation: isolate; min-height: 80vh; color: #0b1f3a;}.hero-sky { position: absolute; inset: 0; z-index: -1; background: linear-gradient(0deg, #d6ecf8, #8ec4ec 45%, #3b7fd4);}import { start } from '@dioramajs/diorama'
export const app = start({ canvas: 'behind' })The CSS fallbacks of the other styles are linear-gradient(0deg, #ffb26e, #ee7d8c 45%, #37397f) for sunset and linear-gradient(0deg, #1e2e54, #101b38 45%, #050a19) for night.
A night sky for a sleep app
night draws a dark sky with stars and clouds lit by the moon. A low cover and a slow speed keep it calm.
Live preview needs WebGPU or WebGL 2. A dark blue night sky with stars, a small moon and a few moonlit clouds drifting slowly.
This example failed to draw.
<div class="cl-night" aria-hidden="true" data-dio="clouds" data-dio-style="night" data-dio-cover="0.35" data-dio-speed="0.12"></div>Clouds that part on scroll
scroll moves the layers apart as the section crosses the viewport, nearer ones more, so the sky has depth while visitors read. With fps at 0 the clouds move only with the scroll and draw nothing at rest.
<section class="story"> <div class="story-sky" aria-hidden="true" data-dio="clouds" data-dio-style="sunset" data-dio-scroll="0.8" data-dio-fps="0" ></div> <h2>Evenings on the terrace</h2></section>Readable text
day: dark navy text such as#0b1f3areads on both the sky and the clouds whilecoverstays at 0.5 or below. Over heavy cloud, put the text on a card.sunsetandnight: white text. Undersunset, keep the heading in the upper half, where the sky is darkest.sunat 0 removes the bright glow when it sits right behind the heading.
Notes
The docs canvas sits above the page, so the examples here keep text beside the sky. Put text over the clouds with canvas: 'behind', as in the first recipe.
The style chooses the whole palette: sky, cloud light and shade, and the sun or the moon. There are no color params yet.
It draws up to fps frames a second while it is on screen and none off screen; the pointer and scroll draw at full rate while they shift the layers. On the low tier it draws one layer of clouds at most 15 frames a second, on the medium tier two layers at 24.
style, layers and seed rebuild the effect when they change. Cover, speed, size, sun and parallax change live.