Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

clouds

BackgroundsAlso inScroll scenes

@dioramajs/backgrounds/cloudsSource

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.

View as Markdown
On this page

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.

Switch style to sunset or night, or move cover to clear the sky.
Params of clouds
style

day a blue sky with white clouds, for travel, airline and kids’ sites.

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.

Terminal window
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.

ParamTypeDefaultDescription
stylerebuildsdata-dio-style'day' | 'sunset' | 'night''day'
  • day a blue sky with white clouds, for travel, airline and kids’ sites.
  • sunset an orange and violet sky with peach clouds, for hotels, resorts and evening events.
  • night a dark sky with stars and moonlit clouds, for sleep, night events and dark themes.
coverdata-dio-covernumber0 to 10.5How much of the sky the clouds cover; 0 a clear sky, 1 overcast.
speeddata-dio-speednumber0 to 10.2Wind speed; 0 holds the clouds in place.
scaledata-dio-scalenumber0.3 to 31Size of the clouds.
sundata-dio-sunnumber0 to 10.6Brightness of the sun or the moon, its glow and the light on cloud edges; 0 hides it.
depthdata-dio-depthnumber0 to 10.2How far the layers shift apart with the pointer; 0 ignores the pointer.
scrolldata-dio-scrollnumber0 to 10.3How far the layers move while the element crosses the viewport, nearer ones more; 0 keeps them.
layersrebuildsdata-dio-layersnumber1 to 33Layers of clouds, 1 to 3.At most low 1, medium 2 by quality tier.
fpsdata-dio-fpsnumber0 to 6030Most frames a second the wind draws; 0 holds it still.At most low 15, medium 24 by quality tier.
seedrebuildsdata-dio-seednumber1 to 1001Shapes 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.

TierWhat changes
lowAt most 15 frames a second and one layer of clouds.
mediumAt 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);
}
src/main.ts
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.

Params of clouds
<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 #0b1f3a reads on both the sky and the clouds while cover stays at 0.5 or below. Over heavy cloud, put the text on a card.
  • sunset and night: white text. Under sunset, keep the heading in the upper half, where the sky is darkest.
  • sun at 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.