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

blobs

Backgrounds

@dioramajs/backgrounds/blobsSource

Soft blobs of brand color drifting behind a hero: merging like a lava lamp, as blurred orbs or as glossy glass drops.

View as Markdown
On this page

Live now, 1,204 listening

Night Drift radio

Slow electronic music around the clock, picked by hand. No ads, no talking, just the next track.

Start listening

Live preview needs WebGPU or WebGL 2. A radio station card with soft violet, cyan, pink and gold blobs drifting and merging over dark navy, beside the station name.

This example failed to draw.

Switch style to orbs for blurred discs or to glass for glossy drops.
Params of blobs
style

lava merges the blobs like a lava lamp, for SaaS and startup heroes.

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 blobs, 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 blobs
<article class="bl-radio">
<div class="bl-lava" aria-hidden="true" data-dio="blobs"></div>
<div class="bl-info">
<p class="bl-kicker">Live now, 1,204 listening</p>
<h2>Night Drift radio</h2>
<p>Slow electronic music around the clock, picked by hand. No ads, no talking, just the next track.</p>
<a href="/listen">Start listening</a>
</div>
</article>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.bl-lava', 'blobs', {
style: 'lava',
count: 6,
color1: '#6d5dfc',
color2: '#22d3ee',
color3: '#f472b6',
color4: '#fbbf24',
background: '#0b1026',
scale: 1,
softness: 0.3,
warp: 0.3,
speed: 0.15,
attract: 0.2,
scroll: 0.25,
grain: 0.03,
fps: 30,
})
import { start } from '@dioramajs/diorama'
import blobs from '@dioramajs/backgrounds/blobs'
const app = start()
app.attach('.bl-lava', blobs({
style: 'lava',
count: 6,
color1: '#6d5dfc',
color2: '#22d3ee',
color3: '#f472b6',
color4: '#fbbf24',
background: '#0b1026',
scale: 1,
softness: 0.3,
warp: 0.3,
speed: 0.15,
attract: 0.2,
scroll: 0.25,
grain: 0.03,
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'lava' | 'orbs' | 'glass''lava'
  • lava merges the blobs like a lava lamp, for SaaS and startup heroes.
  • orbs draws separate blurred discs, for frosted glass cards over them.
  • glass shades the merged shapes as glossy drops, for product and app launches.
countdata-dio-countnumber0 to 86How many blobs show, up to 8; a fraction fades the last one in; 0 leaves the background.At most low 4 by quality tier.
color1data-dio-color1color'#6d5dfc'Color of the first and fifth blobs, any CSS color.
color2data-dio-color2color'#22d3ee'Color of the second and sixth blobs.
color3data-dio-color3color'#f472b6'Color of the third and seventh blobs.
color4data-dio-color4color'#fbbf24'Color of the fourth and eighth blobs.
backgrounddata-dio-backgroundcolor'#0b1026'Color between the blobs.
scaledata-dio-scalenumber0.3 to 2.51Size of the blobs.
softnessdata-dio-softnessnumber0 to 10.3How soft the edges are: 0 crisp shapes, 1 a wide blur; with orbs, the blur of each disc.
warpdata-dio-warpnumber0 to 10.3How much noise wobbles the edges; 0 keeps them round.
speeddata-dio-speednumber0 to 10.15How fast the blobs travel; 0 holds them in place.
attractdata-dio-attractnumber0 to 10.2How far the blobs lean toward the pointer while it is over the element; 0 ignores it.
scrolldata-dio-scrollnumber0 to 10.25How far the blobs move along their paths while the element crosses the viewport.
graindata-dio-grainnumber0 to 0.20.03Strength of the film grain, one CSS pixel per grain; 0 leaves only the dithering.
fpsdata-dio-fpsnumber0 to 6030Most frames a second the drift draws; 0 holds it still.At most low 15, medium 24 by quality tier.
seedrebuildsdata-dio-seednumber1 to 1001Paths, sizes and rhythms of the blobs.

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 frame: the blobs and the grain stop, and neither the pointer nor scroll moves them.

Runs on every device. The blobs lean toward 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: { blobs: { reducedMotion: 'off' } } })

Cost and quality

Download
2.6 KB min+gzip the first time a page uses it
GPU
One pass over the element: one read of a small noise tile and a few operations per blob and pixel.
Memory
A 64 × 64 noise tile shared with gradient.
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 4 blobs.
mediumAt most 24 frames a second.

Recipes

Behind a SaaS hero

Put the blobs on an empty aria-hidden element that fills the hero and start the app with canvas: 'behind', so the heading and buttons sit over the canvas. The element’s CSS background is what visitors see before the engine draws and without WebGL, so give it the same background color.

<header class="hero">
<div
class="hero-bg"
aria-hidden="true"
data-dio="blobs"
data-dio-color1="#4f46e5"
data-dio-color2="#06b6d4"
data-dio-color3="#ec4899"
data-dio-color4="#f59e0b"
data-dio-background="#0b1026"
></div>
<h1>Deploys you never think about</h1>
<a class="cta" href="/signup">Start for free</a>
</header>
.hero {
position: relative;
isolation: isolate;
min-height: 80vh;
color: #fff;
}
.hero-bg {
position: absolute;
inset: 0;
z-index: -1;
background: #0b1026;
}
src/main.ts
import { start } from '@dioramajs/diorama'
export const app = start({ canvas: 'behind' })

Orbs behind frosted glass cards

orbs keeps the blobs apart as blurred discs, the look behind glass cards with backdrop-filter. On a light page use pale brand colors and a near-white background.

<section class="plans">
<div
class="plans-bg"
aria-hidden="true"
data-dio="blobs"
data-dio-style="orbs"
data-dio-count="4"
data-dio-softness="0.6"
data-dio-background="#f5f3ff"
data-dio-color1="#a78bfa"
data-dio-color2="#67e8f9"
data-dio-color3="#f9a8d4"
data-dio-color4="#fde68a"
></div>
<div class="card">Pro, $12 a month</div>
</section>
.card {
background: rgb(255 255 255 / 0.55);
backdrop-filter: blur(16px);
}

Glass drops for a launch

glass shades the merged shapes as glossy drops with a highlight and a bright rim. It reads best on a dark background with three to five drops and no grain.

Live preview needs WebGPU or WebGL 2. Five glossy drops in brand colors drifting and merging over a near-black background.

This example failed to draw.

Params of blobs
<div
class="bl-glass"
aria-hidden="true"
data-dio="blobs"
data-dio-style="glass"
data-dio-count="5"
data-dio-scale="1.2"
data-dio-grain="0"
data-dio-background="#0e0f1a"
data-dio-seed="3"
></div>

Readable text

Text sits over the blobs, so pick colors with contrast in mind:

  • On a dark background such as #0b1026, set the heading in white and keep the blobs saturated but not near white. Keep grain at 0.05 or below under body text.
  • On a light background such as #f5f3ff, use pale blobs and dark text such as #1b1530; orbs with softness around 0.6 keeps hard edges away from the letters.
  • Lower count or scale when a blob keeps drifting under the heading, or put the heading on a card.

Notes

The docs canvas sits above the page, so the examples here draw nothing over the blobs. Put text over them with canvas: 'behind', as in the first recipe.

Unlike gradient, which fills the whole box with one wash, blobs draws distinct shapes with the background between them. Colors mix in OKLab where two blobs merge, and every pixel is dithered.

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 move the blobs. With attract at 0 the pointer draws nothing. On the low tier it draws at most 15 frames a second and 4 blobs.

style and seed rebuild the effect when they change. Count, colors, sizes and speeds change live.