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

beam

Blocks and cards

@dioramajs/blocks/beamSource

A light beam that runs around the rounded border of a feature card, an input field or a highlight box.

View as Markdown
On this page

New in 4.2

Realtime sync

Every edit lands on every device in under 100 ms, even on a train with one bar of signal.

Read the changelog

Live preview needs WebGPU or WebGL 2. A dark feature card announcing realtime sync, with an orange-to-violet beam running around its rounded border.

This example failed to draw.

Switch the motion, or move the sliders. With motion hover, point at the card or tab into its link.
Params of beam
motion

loop runs all the time.

Usage

Put it on any element with a box: a card, a form field wrapper, a pricing plan, a callout. start() registers beam, 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 beam
<div class="features">
<article class="feature" data-dio="beam">
<p class="label">New in 4.2</p>
<h3>Realtime sync</h3>
<p>Every edit lands on every device in under 100 ms, even on a train with one bar of signal.</p>
<a href="/features">Read the changelog</a>
</article>
</div>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.feature', 'beam', {
motion: 'loop',
length: 240,
speed: 200,
thickness: 2,
glow: 0.8,
})
import { start } from '@dioramajs/diorama'
import beam from '@dioramajs/blocks/beam'
const app = start()
app.attach('.feature', beam({
motion: 'loop',
length: 240,
speed: 200,
thickness: 2,
glow: 0.8,
}))

Page transitions

The beam fades with the page as it leaves. How a flight flies.

Params

Every param is also an attribute, and both app.attach() and the handle take it by name.

ParamTypeDefaultDescription
motionrebuildsdata-dio-motion'loop' | 'pulse' | 'hover''loop'
  • loop runs all the time.
  • pulse sweeps from the top now and then.
  • hover on hover or focus.
colordata-dio-colorcolor'#ffaa40'Color of the beam’s head, any CSS color.
color2data-dio-color2color'#9c40ff'Color the trail turns into toward its end, any CSS color.
lengthdata-dio-lengthnumber20 to 600 px240Length of the beam with its trail along the border.
speeddata-dio-speednumber0 to 1000 px/s200Speed along the border; 0 stops the beam where it is.
thicknessdata-dio-thicknessnumber0.5 to 8 px2Thickness of the line.
glowdata-dio-glownumber0 to 20.8Strength and reach of the soft light around the line; 0 draws the line alone.
fpsdata-dio-fpsnumber0 to 12060Most frames a second while the beam runs; 0 holds it still.At most low 30, medium 45 by quality tier.

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, height, motion, opacity, reducedMotion, size and width . Draws at a steady rate while it is on screen and stops when it leaves. At most fps a second while on screen for loop and pulse; for hover only while hovered, focused or fading out, none at rest. 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. Static: a faint still border in the two colors instead of the moving beam; with hover it shows while hovered or focused.

Runs on every device. A tap runs the hover beam while the finger is down; a focused field keeps it running.

To change what reduced motion does, patch it in start().

import { start } from '@dioramajs/diorama'
start({ effects: { beam: { reducedMotion: 'off' } } })

Cost and quality

Download
2.3 KB min+gzip the first time a page uses it
GPU
One draw of a thin frame around the box; the inside of the element is never shaded.
Memory
Eight vertices.
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 30 frames a second.
mediumAt most 45 frames a second.

Recipes

A field that lights up while you type

With motion="hover" the beam runs while the pointer is over the element or focus is inside it, so a wrapped email field keeps its beam while someone types. Cool colors suit a form; a shorter length keeps the beam tidy on a short pill.

Live preview needs WebGPU or WebGL 2. A newsletter form on a navy page whose email field lights up with a blue beam on hover and focus.

This example failed to draw.

<form class="signup" action="#signup">
<h3>Get the launch notes</h3>
<label
class="field"
data-dio="beam"
data-dio-motion="hover"
data-dio-color="#38bdf8"
data-dio-color2="#6366f1"
data-dio-length="120"
>
<input
type="email"
name="email"
placeholder="you@company.com"
aria-label="Email address"
/>
</label>
<button type="submit">Subscribe</button>
</form>

Notes

The element stays DOM: the beam draws over its edge on the canvas, as a thin frame around the box, so the inside of a large card costs nothing. It follows the largest of the element’s corner radii, so give all four corners the same border-radius. The line sits inside the edge, where a 1 or 2 px CSS border is, and the glow spreads to both sides of it.

motion="loop" and motion="pulse" draw at most fps frames a second while the element is on screen and nothing while it is off screen or the tab is hidden; fps="0" holds the beam where it is. With motion="hover" nothing is drawn at rest.

Under reduced motion the beam stands still as a faint border in its two colors.

motion rebuilds the effect when it changes; the other params change live.