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

shine

Blocks and cardsAlso inPhoto

@dioramajs/blocks/shineSource

A glint that sweeps across a button, a card or an image on hover, on a timer or as it comes into view.

View as Markdown
On this page

Team

$49 per month

  • Up to 25 editors
  • Shared design library
  • Version history for a year
Upgrade to Team

Live preview needs WebGPU or WebGL 2. A white pricing card for a Team plan whose violet upgrade button catches a glint every three seconds.

This example failed to draw.

Switch the trigger, or move the sliders. With trigger hover, point at the button; on a phone, tap it.
Params of shine
trigger

interval also sweeps on a timer while on screen, for a call to action.

Usage

Put it on any element: a button, a link, a pricing card, a badge, an image. start() registers shine, 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 shine
<div class="pricing">
<article class="plan">
<p class="tier">Team</p>
<p class="price"><strong>$49</strong> per month</p>
<ul>
<li>Up to 25 editors</li>
<li>Shared design library</li>
<li>Version history for a year</li>
</ul>
<a
class="upgrade"
href="/pricing"
data-dio="shine"
data-dio-trigger="interval"
data-dio-interval="3"
>Upgrade to Team</a>
</article>
</div>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.upgrade', 'shine', {
trigger: 'interval',
angle: 120,
width: 0.35,
duration: 1.1,
interval: 3,
strength: 0.5,
})
import { start } from '@dioramajs/diorama'
import shine from '@dioramajs/blocks/shine'
const app = start()
app.attach('.upgrade', shine({
trigger: 'interval',
angle: 120,
width: 0.35,
duration: 1.1,
interval: 3,
strength: 0.5,
}))

Page transitions

A sweep 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
triggerrebuildsdata-dio-trigger'hover' | 'interval' | 'view''hover'
  • hover sweeps on pointer enter and keyboard focus.
  • interval also sweeps on a timer while on screen, for a call to action.
  • view sweeps once as it comes into view, for a badge or a plan.
angledata-dio-anglenumber0 to 360°120Direction of the sweep, like a CSS gradient angle; 90 goes left to right.
widthdata-dio-widthnumber0.05 to 10.35Width of the band as a share of the element’s length along the sweep.
colordata-dio-colorcolor'#ffffff'Color of the band, any CSS color.
durationdata-dio-durationnumber0.2 to 4 s1.1Time one sweep takes.
intervaldata-dio-intervalnumber0 to 20 s4Pause between timed sweeps with the interval trigger; 0 sweeps on hover only.
strengthdata-dio-strengthnumber0 to 10.5Opacity of the band at its core; 0 hides it.

Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.

Inputs and frames

It reads opacity, presence and size . Draws only while something on it moves, then stops. Only during a sweep; none at rest and none while waiting for the next timed sweep. 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 element is unchanged.

Runs on every device. A tap sweeps like a hover; the interval and view triggers work as on desktop.

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

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

Cost and quality

Download
1.9 KB min+gzip the first time a page uses it
GPU
One quad over the element, drawn only during a sweep.
Memory
None beyond the quad.
Frames
Idle at rest

It runs from the low tier up. Every tier draws it the same way. The quality plugin picks the tier for each device.

Recipes

On a pricing table, the plan you recommend can catch the light as the pointer comes over it. A narrower width and a lower strength keep the band subtle on a large card.

Starter

$0 per month

One project, community support.

Agency

$99 per month

Client workspaces and white labeling.

Live preview needs WebGPU or WebGL 2. Three pricing plans on a warm page; the dark featured Studio plan glints when the pointer enters it.

This example failed to draw.

<div class="plans">
<article class="option">
<h3>Starter</h3>
<p><strong>$0</strong> per month</p>
<p>One project, community support.</p>
</article>
<article
class="option featured"
data-dio="shine"
data-dio-width="0.25"
data-dio-strength="0.3"
>
<h3>Studio</h3>
<p><strong>$29</strong> per month</p>
<p>Unlimited projects, priority support.</p>
</article>
<article class="option">
<h3>Agency</h3>
<p><strong>$99</strong> per month</p>
<p>Client workspaces and white labeling.</p>
</article>
</div>

A badge that glints as it shows up

The view trigger sweeps once the first time half of the element is in view. A warm color and a stronger strength suit a gold member badge or an award seal.

Gold member

Welcome back, Dana

Free shipping and early access to every drop are on for your account.

Live preview needs WebGPU or WebGL 2. A gold member badge above a welcome message, sweeping once as it scrolls into view.

This example failed to draw.

<section class="member">
<span
class="badge"
data-dio="shine"
data-dio-trigger="view"
data-dio-color="#fff4cc"
data-dio-strength="0.65"
data-dio-duration="1.2"
>Gold member</span>
<h3>Welcome back, Dana</h3>
<p>Free shipping and early access to every drop are on for your account.</p>
</section>

Notes

The element stays DOM: the band draws over it on the canvas only during a sweep and is clipped to the element’s own border-radius, corner by corner, so pill buttons work too. A parent with overflow: hidden does not clip it, so keep the element fully inside such a parent. Between sweeps nothing is drawn, and the interval trigger waits on a timer without drawing frames. Timed sweeps pause while the element is off screen or the tab is hidden.

Keyboard focus on the element or a control inside it sweeps like a hover, and a tap sweeps on touch screens.

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

trigger rebuilds the effect when it changes; the other params change live and apply to the next sweep.