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.
In this step you check the page from the previous steps with reduced motion and on a touch device, and decide per effect what those visitors get. You change two effects with one option each: shimmer turns off with reduced motion, and torch turns off on touch devices.
Turn on reduced motion
Open DevTools, then the Rendering panel (in the Command Menu, Ctrl+Shift+P, type Rendering). Set “Emulate CSS media feature prefers-reduced-motion” to reduce. Diorama follows the setting at once, without a reload.
Live preview needs WebGPU or WebGL 2. Three prints with ripple, torch and shimmer, and a checkbox that emulates reduced motion: with it on, all three show the plain image.
This example failed to draw.
The checkbox emulates the setting for this whole page, the same way the Rendering panel does.
<divclass="trio">
<img
src="/media/prints/dawn.jpg"
width="300"
height="300"
data-dio="ripple"
/>
<img
src="/media/prints/dusk.jpg"
width="300"
height="300"
data-dio="torch"
/>
<img
src="/media/prints/night.jpg"
width="300"
height="300"
data-dio="shimmer"
/>
</div>
import{ effect }from'@dioramajs/diorama'
import{ fract, smoothstep, vec4 }from'three/tsl'
exportdefaulteffect(
{speed:0.25,width:0.15},
{reducedMotion:'off'},
({ surface, u })=>{
surface.color((color,{ box })=>{
const at =fract(u.time.mul(u.speed)).mul(2).sub(0.5)
const d = box.x.add(box.y).mul(0.5).sub(at).abs()
const band =smoothstep(0, u.width, d).oneMinus().mul(0.35)
returnvec4(color.rgb.add(band), color.a)
})
},
)
import{ effect }from'@dioramajs/diorama'
import{ smoothstep, vec4 }from'three/tsl'
exportdefaulteffect(
{radius:0.35,dim:0.6},
{when:'hover'},
({ surface, u })=>{
surface.color((color,{ box })=>{
const d = box.sub(u.pointer).mul(u.size).length().div(u.size.y)
ripple and torch show the plain image. They read u.hover, which stays 0 with reduced motion.
shimmer stands still. u.time and u.hoverTime stop, and the effect asks for no frames.
bend does not curve. u.velocity, the scroll speed, stays 0.
The thumbnail from the previous step does not fly. It fades out in place in 0.2 seconds, and the cover appears in its own place.
This is the default, reducedMotion: 'static': the effect still runs, with motion inputs at 0 and time stopped. u.pointer keeps working, because the visitor moves it.
Turn an effect off with reduced motion
A still frame is not always a good picture. If the setting changes while the page is open, u.time stops where it is, and the shimmer band can stop in the middle of the image. Pass reducedMotion: 'off' and the image stays plain HTML with reduced motion.
src/effects/shimmer.ts
import{
functioneffect(
setup:EffectSetup<Empty>
):Effect<Empty>(+2overloads)
Short form of defineEffect: defaults, optional options, setup. An unnamed effect takes its
registry key (the file name when a build plugin finds it).
Open the Elements panel and select the image. With reduced motion it has data-dio-state="off" and shows as plain HTML; turn the emulation off and the state goes to drawn as the effect starts again.
To keep an effect but drop only its motion, multiply the moving part by u.motion, which is 1 normally and 0 with reduced motion.
Turn an effect off on touch
A touch screen has no pointer that hovers, so torch has nothing to follow. Pass when: 'hover': the effect runs only where the page matches the media query (hover: hover).
src/effects/torch.ts
import{
functioneffect(
setup:EffectSetup<Empty>
):Effect<Empty>(+2overloads)
Short form of defineEffect: defaults, optional options, setup. An unnamed effect takes its
registry key (the file name when a build plugin finds it).
ripple comes with when: 'hover' already. when takes any media query, for example '(min-width: 800px)'.
To check it, turn on the device toolbar (Ctrl+Shift+M in DevTools), pick a phone and reload the page. The image with torch has data-dio-state="off" and shows as plain HTML. If no other element on the page needs the engine, it does not start on the phone at all.
Why it works
Every effect decides what it does with reduced motion and on touch in its definition, so a page cannot forget one of its images. An effect that is off leaves its element as plain HTML, which costs nothing: no layer, no frames, and the engine does not start for it.
The same plain HTML is what visitors see when Diorama cannot run: on a browser without WebGPU or WebGL 2, and with Save-Data on, where start() does not load the engine. Give every image its alt text and its size, and the page works for them without a canvas.