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

carousel

Galleries and viewersAlso in3D and product

@dioramajs/media/carouselSource

Pictures on a 3D ring that turns with a drag, the keys, the page scroll or by itself, the front one enlarged.

View as Markdown
On this page
  • The headland: a grassy point dropping into the sea under a pale sky
  • The boulder beach: rounded stones at the edge of the water
  • The islets: dark rocks in a blue bay, a flat-topped mountain in the haze
  • The point break: surf over brown rocks at the foot of the cliffs
  • The cliff path: a green slope falling to the sea
  • The white shore: pale rocks and low bushes above a grey sea

Live preview needs WebGPU or WebGL 2. Six coastal places on a ring seen from slightly above, the front one larger and mirrored on the floor; drag, swipe or use the arrow keys to turn it.

This example failed to draw.

The images stand around a ring seen a little from above, the front one larger, the ones at the back smaller and darker, with an optional reflection on the floor. A drag, a sideways wheel or the arrow keys turn the ring and it settles with a picture at the front; a click on a picture turns it to the front, a click on the front one follows its link. In inside the viewer stands at the middle of the ring and the pictures curve around like a wall. Autoplay steps or drifts round, with a pause button over the corner of the box.
Params of carousel
style

ring shows the ring from outside, the pictures facing out.

motion

step rests on each picture for interval seconds and moves on.

by

drag turns the ring by pointer, wheel, keys, clicks and autoplay.

Usage

Put it on a list of linked images: products, a team, projects. start() registers carousel, 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 carousel
<ul
class="coast"
data-dio="carousel"
data-dio-reflection="0.25"
aria-label="Six places on the coast. Drag, swipe or use the arrow keys to turn the ring; the picture at the front opens its place."
style="touch-action: pan-y"
>
<li>
<a href="/headland">
<img
src="/media/coast/headland-800.avif"
width="800"
height="534"
/>
</a>
</li>
<li>
<a href="/boulders">
<img
src="/media/coast/boulders-600.avif"
width="600"
height="750"
/>
</a>
</li>
<li>
<a href="/islets">
<img
src="/media/coast/islets-600.avif"
width="600"
height="600"
/>
</a>
</li>
<li>
<a href="/surf">
<img
src="/media/coast/surf-800.avif"
width="800"
height="534"
/>
</a>
</li>
<li>
<a href="/slope">
<img
src="/media/coast/slope-800.avif"
width="800"
height="534"
/>
</a>
</li>
<li>
<a href="/shore">
<img
src="/media/coast/shore-800.avif"
width="800"
height="534"
/>
</a>
</li>
</ul>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.coast', 'carousel', {
style: 'ring',
motion: 'step',
by: 'drag',
spacing: 0.4,
tilt: 8,
focus: 1.15,
shade: 0.5,
reflection: 0.25,
perspective: 1200,
duration: 0.7,
})
import { start } from '@dioramajs/diorama'
import carousel from '@dioramajs/media/carousel'
const app = start()
app.attach('.coast', carousel({
style: 'ring',
motion: 'step',
by: 'drag',
spacing: 0.4,
tilt: 8,
focus: 1.15,
shade: 0.5,
reflection: 0.25,
perspective: 1200,
duration: 0.7,
}))

Events

It dispatches these on its element; they bubble.

  • dio:index, detail: { index: number }. A picture reached the front after a turn; index is its place among the images, from 0. Bubbles.
  • dio:open, detail: { index: number }. The front picture was clicked and its image is in no link or button; index is its place. Bubbles.

Parts

Its own controls take your styles through ::part().

  • pause: The pause button of autoplay, after the list in the page; aria-pressed says whether it holds.

Page transitions

Fades with the page transition. How a flight flies.

Params

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

ParamTypeDefaultDescription
indexdata-dio-indexnumber0 to 100Picture at the front from 0; a fraction holds the ring between two, for a tween.
stylerebuildsdata-dio-style'ring' | 'inside''ring'
  • ring shows the ring from outside, the pictures facing out.
  • inside puts the viewer at its middle, the pictures facing in and curving away at the sides.
byrebuildsdata-dio-by'drag' | 'scroll''drag'
  • drag turns the ring by pointer, wheel, keys, clicks and autoplay.
  • scroll turns it once round as the list crosses the viewport, for a showcase in a long page.
motionrebuildsdata-dio-motion'step' | 'drift''step'
  • step rests on each picture for interval seconds and moves on.
  • drift turns slowly and steadily, a picture every interval seconds.
intervaldata-dio-intervalnumber0 to 10 s0Seconds per picture of autoplay, 0 for none.
radiusrebuildsdata-dio-radiusnumber | 'auto'1 to 2000 px'auto'Radius of the ring in px; auto sizes it so the pictures stand spacing apart.
spacingdata-dio-spacingnumber0 to 20.4Gap between pictures on the ring, in widths of a picture.
tiltdata-dio-tiltnumber-30 to 30°8How far from above the ring is seen; 0 at eye level.
focusdata-dio-focusnumber1 to 21.15Size of the front picture against the others; 1 for the same.
shadedata-dio-shadenumber0 to 10.5Darkening of the pictures at the back, 0 for none.
reflectiondata-dio-reflectionnumber0 to 10Opacity of the pictures mirrored on the floor, 0 for none.At most low 0 by quality tier.
perspectivedata-dio-perspectivenumber300 to 4000 px1200Distance of the eye from the ring, like CSS perspective; lower is stronger.
durationdata-dio-durationnumber0.15 to 3 s0.7Length of a turn by one picture.
dragdata-dio-dragbooleantrueA drag or a swipe turns the ring.
wheeldata-dio-wheelbooleantrueA sideways wheel or trackpad swipe turns the ring.
clickdata-dio-clickbooleantrueA click on a picture turns it to the front.
pausedata-dio-pausebooleantrueShows the pause button while autoplay runs; off, the page must give a control of its own.
itemsrebuildsdata-dio-itemsstring'img'Selector of the images inside the list.

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, reducedMotion, size, width, x and y . Draws only while something on it moves, then stops. While the ring turns and the whole time drift plays; with step autoplay only during each step. 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. No autoplay and no pause button, no turning with the page scroll; changes are at once. Keys, clicks and swipes still turn the ring.

Runs on every device. A swipe turns the ring with touch-action: pan-y on the list; without it the browser scrolls the list and the ring follows that scroll. A tap on a picture turns it to the front, on the front one follows its link.

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

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

Cost and quality

Download
8.3 KB min+gzip the first time a page uses it
GPU
A quad per picture, up to 24, one texture read per pixel; the reflection doubles the pixels of each.
Memory
Every picture on the ring.
Frames
Idle at rest

It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.

TierWhat changes
lowNo reflection.

Recipes

Rooms that turn by themselves, with a pause button

With interval set to 3 the ring rests on each room for 3 seconds and turns on to the next. Content that moves on its own for longer than 5 seconds needs a way to stop it (WCAG 2.2.2), so autoplay brings its own pause button over the bottom right corner of the box. The ring also waits while the pointer is over it, while focus is inside it, in a background tab, and for 4 seconds after someone turns it by hand.

  • The Ocean Room: a king bed with a red throw, doors open to a balcony and the sea
  • The Glass Room: a bed under steel-framed windows looking over dry hills
  • The Garden Room: a double bed in white linen beside a tall window
  • The Loft: a low bed against a brick wall and wide wooden floorboards
  • The Twin Room: a garden window and a tea tray on a wooden stand

Live preview needs WebGPU or WebGL 2. Five hotel rooms on a ring that turns every 3 seconds, a pause button in the corner.

This example failed to draw.

Params of carousel
motion

step rests on each picture for interval seconds and moves on.

<ul
class="suites"
data-dio="carousel"
data-dio-interval="3"
data-dio-tilt="4"
data-dio-focus="1.25"
aria-label="Five rooms of the hotel, turning by themselves; the button in the corner pauses them."
style="touch-action: pan-y"
>
<li>
<img
src="/media/rooms/ocean.avif"
width="1200"
height="900"
/>
</li>
<li>
<img
src="/media/rooms/glass.avif"
width="1200"
height="900"
/>
</li>
<li>
<img
src="/media/rooms/garden.avif"
width="1200"
height="900"
/>
</li>
<li>
<img
src="/media/rooms/studio.avif"
width="1200"
height="900"
/>
</li>
<li>
<img
src="/media/rooms/twin.avif"
width="1200"
height="900"
/>
</li>
</ul>

Set motion to drift for a ring that turns slowly and steadily instead, a room every interval seconds. The button is a real <button> placed right after the list in the page, in the tab order after the pictures; style it from the page with ::part(pause). If the page has a control of its own, set pause to false and let that control set interval to 0.

A curved wall of projects

The inside style puts the viewer in the middle of the ring: the pictures face in and curve away at the sides, like a gallery wall around you. The ones beside and behind you fade out, so it reads well with eight pictures or more.

  • Cyanotype Impressions: white fronds of seaweed on deep blue
  • Atlas of Ice: snow-covered ridges under a pale sky
  • Hare’s Fur: a dark tea bowl with a streaked glaze
  • The Measure of the Sky: the brass face of an astrolabe
  • Polar Night: green aurora over the night side of the Earth
  • Outer Coast: dark cliffs above a grey sea under clouds
  • Sea Steps: concrete steps into a grey sea
  • Tranquility: boulders on grey lunar ground

Live preview needs WebGPU or WebGL 2. Eight project covers on a wall that curves around the viewer.

This example failed to draw.

Params of carousel
<ul
class="wall"
data-dio="carousel"
data-dio-style="inside"
data-dio-tilt="0"
data-dio-focus="1"
data-dio-spacing="0.1"
aria-label="Eight projects on a curved wall. Drag, swipe or use the arrow keys to turn it."
style="touch-action: pan-y"
>
<li>
<a href="/cyanotype">
<img
src="/media/work/cyanotype.webp"
width="1200"
height="800"
/>
</a>
</li>
<li>
<a href="/atlas-of-ice">
<img
src="/media/work/atlas-of-ice.webp"
width="1200"
height="800"
/>
</a>
</li>
<li>
<a href="/hares-fur">
<img
src="/media/work/hares-fur.webp"
width="1200"
height="800"
/>
</a>
</li>
<li>
<a href="/measure-of-the-sky">
<img
src="/media/work/measure-of-the-sky.webp"
width="1200"
height="800"
/>
</a>
</li>
<li>
<a href="/polar-night">
<img
src="/media/work/polar-night.webp"
width="1200"
height="800"
/>
</a>
</li>
<li>
<a href="/outer-coast">
<img
src="/media/work/outer-coast.webp"
width="1200"
height="800"
/>
</a>
</li>
<li>
<a href="/sea-steps">
<img
src="/media/work/sea-steps.webp"
width="1200"
height="800"
/>
</a>
</li>
<li>
<a href="/tranquility">
<img
src="/media/work/tranquility.webp"
width="1200"
height="800"
/>
</a>
</li>
</ul>

Turn with the page scroll

With by set to scroll the ring turns once round while the list crosses the viewport, a showcase that plays as the page goes by. Drags, keys and autoplay are off then, and under reduced motion the ring stands still at index.

<ul
class="range"
data-dio="carousel"
data-dio-by="scroll"
data-dio-tilt="12"
>
<li><img src="/shop/kettle.avif" /></li>
<li><img src="/shop/mug.avif" /></li>
</ul>

Notes

Write the ring as a list of images, in links if each opens a page, styled as the grid or the row you want without WebGL. Each picture takes the size of its image in that layout, so size the images for the ring (the example gives them most of the frame’s height in a row that scrolls), and its picture is cut like the image, with the image’s own object-fit and object-position; the corners follow the border-radius of the first image. The ring stands on the middle line of the list’s box; with radius at auto (the default) it is wide enough that the pictures stand spacing apart, and a ring too wide for the box is drawn smaller as a whole. Up to 24 pictures go on the ring.

The copy hides the list, its background included, so put a background on a parent. A click on a picture is caught by the effect: on a picture at the side it turns that one to the front, on the front one it follows its link, with Ctrl or Cmd in a new tab. An image without a link fires dio:open instead.

The links stay in the page in order with their alt text. Tab moves through them and the ring turns to the focused one; the arrow keys, PageUp, PageDown, Home and End turn the ring and move the focus with it. Without links give the list tabindex="0" and an aria-label that says how to turn it.

A drag with a mouse always turns the ring. On touch screens set touch-action: pan-y on the list so the ring follows the finger while the page still scrolls up and down. Only a sideways wheel or a two-finger swipe on a trackpad turns it; a wheel turned up and down scrolls the page.

style, by, motion and items rebuild the effect when they change. Set them in the markup rather than switching them while the ring is on screen.