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

sparkles

Celebration and particlesAlso inBlocks and cards

@dioramajs/particles/sparklesSource

Small twinkling sparkles around a badge, a "new" label, a premium button or a product highlight.

View as Markdown
On this page

Studio plan New

Unlimited projects, brand kits and 4K export.

Go Pro

Live preview needs WebGPU or WebGL 2. An upgrade panel on a deep violet page with a gold New badge that twinkles all the time and a Go Pro button that sparkles on hover.

This example failed to draw.

Switch the trigger and the style of the button's sparkles, or move the sliders. With trigger hover, point at Go Pro; with click, click it.
Params of sparkles
style

star draws four-point sparkles.

trigger

loop nonstop.

Usage

Put it on any element: a badge, a label, a button, a card, a product photo. start() registers sparkles, 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 sparkles
<div class="upgrade">
<p class="plan">
Studio plan
<span
class="badge"
data-dio="sparkles"
data-dio-scale="0.7"
data-dio-spread="14"
data-dio-trigger="loop"
data-dio-count="6"
>New</span>
</p>
<p class="pitch">Unlimited projects, brand kits and 4K export.</p>
<a
class="pro"
href="/upgrade"
data-dio="sparkles"
data-dio-count="14"
>Go Pro</a>
</div>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.badge', 'sparkles', {
style: 'star',
trigger: 'loop',
count: 6,
scale: 0.7,
spread: 14,
duration: 1.1,
})
import { start } from '@dioramajs/diorama'
import sparkles from '@dioramajs/particles/sparkles'
const app = start()
app.attach('.badge', sparkles({
style: 'star',
trigger: 'loop',
count: 6,
scale: 0.7,
spread: 14,
duration: 1.1,
}))

Page transitions

Sparkles fade 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
triggerrebuildsdata-dio-trigger'hover' | 'click' | 'loop' | 'view''hover'
  • hover on hover or focus.
  • click bursts from the pointer.
  • loop nonstop.
  • view once in view.
stylerebuildsdata-dio-style'star' | 'dot' | 'cross''star'
  • star draws four-point sparkles.
  • dot draws soft round dots.
  • cross draws thin lens glints.
countdata-dio-countnumber1 to 6412Sparkles twinkling at once, or flying out per burst.At most low 8 by quality tier.
scaledata-dio-scalenumber0.25 to 41Size of the sparkles over a base of 30 px.
colordata-dio-colorcolor'#ffd75e'Color of the sparkles, any CSS color; some come out whiter.
spreaddata-dio-spreadnumber0 to 120 px24How far past the element’s edges sparkles appear and bursts fly.
durationdata-dio-durationnumber0.3 to 4 s1.1Life of one sparkle.
fpsdata-dio-fpsnumber0 to 6030Most frames a second of the loop trigger; 0 freezes it.At most low 20 by quality tier.
seedrebuildsdata-dio-seednumber1 to 1001Seed of the randomness.

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, opacity and width . Draws at a steady rate while it is on screen and stops when it leaves. Only while sparkles live: none at rest for hover, click and view; at most fps a second while on screen for loop. How a frame is decided.

Reduced motion and touch

With reduced motion it is off and the element shows as plain HTML. Off: neither the module nor the engine loads for it, and the page is unchanged.

Runs on every device. A tap bursts like a click and starts a few hover sparkles; loop and view work as on desktop.

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

import { start } from '@dioramajs/diorama'
start({ effects: { sparkles: { reducedMotion: 'static' } } })

Cost and quality

Download
2.6 KB min+gzip the first time a page uses it
GPU
One instanced draw of at most 64 small quads, only while sparkles live.
Memory
Instance attributes for 64 sparkles, about 3 KB.
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 8 sparkles and 20 frames a second for loop.

Recipes

A reward when a level is done

On a learning site for kids, trigger="view" bursts once the first time half of the heading is in view. Round dot sparkles in a soft color read as confetti for the very young; a larger spread lets them fly clear of the text.

Level 3 complete!

You matched all twelve animals to their homes.

Live preview needs WebGPU or WebGL 2. A Level 3 complete heading on a cream page that bursts with light blue dots as it comes into view.

This example failed to draw.

<section class="reward">
<h3
data-dio="sparkles"
data-dio-trigger="view"
data-dio-style="dot"
data-dio-count="24"
data-dio-spread="40"
data-dio-color="#7dd3fc"
>Level 3 complete!</h3>
<p>You matched all twelve animals to their homes.</p>
<a class="next" href="/reward">Next level</a>
</section>

Notes

The element stays DOM and keeps every click: the sparkles draw over the page on the canvas, and the click goes on to the link, button or form. A click with the pointer bursts from where it landed; a keyboard click bursts from the element’s edge. Keyboard focus starts the hover sparkles too.

Nothing is drawn at rest with hover, click and view. With loop the sparkles twinkle at most fps frames a second while the element is on screen and stop while it is off screen or the tab is hidden, so keep always for one or two elements a page.

Under reduced motion neither the module nor the engine loads for it, and the element stays as it is.

trigger, style and seed rebuild the effect when they change; the other params change live.