# device

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

The picture becomes the screen of a device built in 3D with the proportions of the real one: a phone with its camera island and side keys, a tablet, an open laptop with its keyboard and trackpad, or a browser window with its toolbar. The picture covers the screen, centered across and from the top down. It rests in a slight three-quarter view, lit by a soft studio light, with a soft shadow on the page under it. It leans toward the pointer and can turn as the page scrolls.

Module `model`, category 3D and product. Import `@dioramajs/model/device`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/model/src/device.ts)

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.

```html title="index.html"
<img class="app-shot" src="/media/device/tidewell-phone.webp" alt="The Tidewell app on a phone: today's tide, water temperature and swim window at Pebble Cove" width="1170" height="2532" data-dio="device" />
```

## 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.

```html
<img src="/shots/app.png" alt="The Tidewell app: today's tasks" width="1170" height="2532" data-dio="device" />
```

In page transitions: Leaves by dithering its pixels away while shrinking to 96%, and its shadow fades with it.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `frame` (rebuilds) | `data-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. |
| `color` | `data-dio-color` | `color` | `'#1d1e22'` | Color of the body, any CSS color; the browser toolbar takes it too. |
| `yaw` | `data-dio-yaw` | `number` -60 to 60° | `-18` | Rest turn around the vertical; negative shows the right side. |
| `pitch` | `data-dio-pitch` | `number` -30 to 30° | `6` | Rest tilt toward the viewer; positive shows it from above. |
| `tilt` | `data-dio-tilt` | `number` 0 to 30° | `6.9` | How far it leans toward the pointer. |
| `turn` | `data-dio-turn` | `number` -360 to 360° | `0` | Turns it as the element passes through the viewport. |
| `radius` | `data-dio-radius` | `number` 0 to 2 | `1` | Corner rounding: 1 is the device as made, 0 square. |
| `shadow` | `data-dio-shadow` | `number` 0 to 1 | `0.5` | Density of the shadow on the page. |
| `scale` | `data-dio-scale` | `number` 0.3 to 1 | `0.9` | Size in the box: 1 fits the device as it is seen in its rest pose, near parts larger in perspective. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `frame`: `phone`, `tablet`, `laptop`, `browser`
  - `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.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`opacity`](/docs/api/inputs#opacity), [`presence`](/docs/api/inputs#presence), [`progress`](/docs/api/inputs#progress), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`width`](/docs/api/inputs#input-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. See [how a frame is decided](/docs/concepts/frames).

## 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.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { device: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 6.0 KB 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.

See [the quality plugin](/docs/effects/quality).

## 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.

A tide dashboard for lifeguards in a light browser window, turned slightly to the left over a dark blue background.

```html title="index.html"
<img class="dashboard" src="/media/device/tidewell-web.webp" alt="The Tidewell dashboard: swimmers per day, beach conditions and the tide at Pebble Cove" 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.

A tide dashboard on a silver laptop, turned to show its right side, on a light warm background.

```html title="index.html"
<img class="laptop-shot" src="/media/device/tidewell-web.webp" alt="The Tidewell dashboard on a laptop: swimmers per day, beach conditions and the tide at Pebble Cove" 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.

```html
<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.

```css
.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`](/docs/effects/model) effect, and the screen keeps the colors of the picture.

## Related

- [book](/docs/effects/book.md): A cover image made a 3D book that turns to show its spine and opens on hover.
- [box](/docs/effects/box.md): A product box built from pictures of its faces: turn it, tilt it, open its lid.
- [coin](/docs/effects/coin.md): A coin, medal or token struck from a logo or a photo: it turns, catches the light and flips over.
- [explode](/docs/effects/explode.md): An exploded view of a model: its parts move apart as the section scrolls.
- [hotspots](/docs/effects/hotspots.md): Feature callouts pinned to points of a model, real buttons that follow it as it turns.
- [label](/docs/effects/label.md): A flat label wrapped around a can, a bottle or a jar that turns to show all of it.
- [model](/docs/effects/model.md): A glTF model fitted into the element, lit, turnable and recolored from markup.
- [panorama](/docs/effects/panorama.md): A 360° photo in a box that turns by drag, keys and gyroscope, with hotspots.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
