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

device

3D and productAlso inPhotoVideo

@dioramajs/model/deviceSource

A screenshot or a video shown in a 3D phone, tablet, laptop or browser window.

View as Markdown
On this page
The Tidewell app on a phone: today's tide, water temperature and swim window at Pebble Cove

Live preview needs WebGPU or WebGL 2. A phone built in 3D around a screenshot of a tide app, resting in a three-quarter view with a soft shadow, leaning toward the pointer.

This example failed to draw.

Move the pointer over the phone. Switch frame to see the app's dashboard in a tablet, a laptop or a browser window, and try color and radius.
Params of device
frame

phone with a camera island and side keys, 16:9 to 19.5:9.

Usage

Put it on img, video: the screenshot or screen recording; the box holds the whole device and shows the plain picture without WebGL. A phone or a tablet takes the box aspect within the range of real ones, a laptop screen is 16:10, a browser window 5:4 to 12:5. start() registers device, 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 device
<img
class="app-shot"
src="/media/device/tidewell-phone.webp"
width="1170"
height="2532"
data-dio="device"
/>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.app-shot', 'device', {
frame: 'phone',
color: '#1d1e22',
yaw: -18,
pitch: 6,
tilt: 6.9,
turn: 0,
radius: 1,
shadow: 0.5,
scale: 0.9,
})
import { start } from '@dioramajs/diorama'
import device from '@dioramajs/model/device'
const app = start()
app.attach('.app-shot', device({
frame: 'phone',
color: '#1d1e22',
yaw: -18,
pitch: 6,
tilt: 6.9,
turn: 0,
radius: 1,
shadow: 0.5,
scale: 0.9,
}))

Page transitions

Leaves by dithering its pixels away while shrinking to 96%, and its shadow fades with it. How a flight flies.

Params

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

ParamTypeDefaultDescription
framerebuildsdata-dio-frame'phone' | 'tablet' | 'laptop' | 'browser''phone'
  • phone with a camera island and side keys, 16:9 to 19.5:9.
  • tablet 4:3 to 16:10.
  • laptop open with its keyboard, a 16:10 screen.
  • browser a window with a toolbar, 5:4 to 12:5.
colordata-dio-colorcolor'#1d1e22'Color of the body, any CSS color; the browser toolbar takes it too.
yawdata-dio-yawnumber-60 to 60°-18Rest turn around the vertical; negative shows the right side.
pitchdata-dio-pitchnumber-30 to 30°6Rest tilt toward the viewer; positive shows it from above.
tiltdata-dio-tiltnumber0 to 30°6.9How far it leans toward the pointer.
turndata-dio-turnnumber-360 to 360°0Turns it as the element passes through the viewport.
radiusdata-dio-radiusnumber0 to 21Corner rounding: 1 is the device as made, 0 square.
shadowdata-dio-shadownumber0 to 10.5Density of the shadow on the page.
scaledata-dio-scalenumber0.3 to 10.9Size in the box: 1 fits the device as it is seen in its rest pose, near parts larger in perspective.

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, presence, progress, reducedMotion and width . Draws only while something on it moves, then stops. Only while it leans toward the pointer, settles, or eases to a new rest pose, plus scroll frames with turn and video frames while a video plays. 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. It rests in its pose: no lean, no scroll turn, and a new pose is taken at once.

Runs on every device. Nothing hovers, so it rests in its pose; turn still follows the scroll.

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

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

Cost and quality

Download
6.0 KB min+gzip the first time a page uses it
GPU
A few hundred triangles lit by one prefiltered environment, the screen as one texture read.
Memory
The picture or the video frame, and the environment map.
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

A dashboard in a browser window

The browser frame adds a toolbar with the window buttons and an address field above the page, and no bezel at the sides, so a wide product screenshot keeps its size. color paints the toolbar: a light gray for a light app, a dark one for a dark app. A smaller yaw keeps a wide window readable.

The Tidewell dashboard: swimmers per day, beach conditions and the tide at Pebble Cove

Live preview needs WebGPU or WebGL 2. A tide dashboard for lifeguards in a light browser window, turned slightly to the left over a dark blue background.

This example failed to draw.

Params of device
<img
class="dashboard"
src="/media/device/tidewell-web.webp"
width="2560"
height="1600"
data-dio="device"
data-dio-frame="browser"
data-dio-color="#e4e8ea"
data-dio-yaw="-12"
data-dio-pitch="4"
/>

A laptop on a product page

The laptop frame is an open laptop: a 16:10 screen in a thin lid with its camera, the keyboard and the trackpad on the deck, the whole machine tipped a little toward the viewer so the keyboard shows. A light color makes a silver one. Give it a wide box: the base needs room under the screen.

The Tidewell dashboard on a laptop: swimmers per day, beach conditions and the tide at Pebble Cove

Live preview needs WebGPU or WebGL 2. A tide dashboard on a silver laptop, turned to show its right side, on a light warm background.

This example failed to draw.

Params of device
<img
class="laptop-shot"
src="/media/device/tidewell-web.webp"
width="2560"
height="1600"
data-dio="device"
data-dio-frame="laptop"
data-dio-color="#c8cad0"
data-dio-yaw="-24"
data-dio-pitch="8"
/>

A screen recording that turns with the page

A <video> works the same as an <img>: the screen plays it, and the effect draws only while a frame is new. turn turns the device by that many degrees while it crosses the viewport, so the laptop swings into view as the visitor scrolls.

<video
src="/media/tour.mp4"
poster="/media/tour.jpg"
autoplay
muted
loop
playsinline
data-dio="device"
data-dio-frame="laptop"
data-dio-color="#c8cad0"
data-dio-turn="54"
></video>

Size the box for the whole device

The device fits inside the element’s box at scale of its size, bezels and base included, as it is seen in its rest pose: its near parts look larger in perspective, so it is measured with them and centered on what is drawn. Give the image the size the device should take on the page, with the aspect ratio of the screenshot, and the plain screenshot shows in the same box without WebGL.

.app-shot {
width: auto;
height: min(80vh, 720px);
aspect-ratio: 1170 / 2532;
}

Notes

Each frame keeps the screen of the real device. A phone or a tablet takes the aspect ratio of the element’s box within the range of real ones, a phone from 16:9 to about 19.5:9 and a tablet from 4:3 to 16:10, upright or on its side as the box is. A laptop screen is always 16:10, and a browser window runs from 5:4 to 12:5. The picture covers the screen as with object-fit: cover, centered across and from the top down, so a tall screenshot in a laptop shows its top. Give each frame a screenshot of its shape, and render it at twice its size on the page or more, so the screen stays sharp on high-density displays.

The device draws its own picture: text in the screenshot is not selectable and not read by assistive technology. Write what the screen shows in the alt text.

The body is lit by the same studio environment as the model effect, and the screen keeps the colors of the picture.