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

horizontal

Scroll scenesAlso inGalleries and viewers

@dioramajs/media/horizontalSource

A row of cards on a pinned stage slides sideways as the page scrolls down, its pictures bending with the speed.

View as Markdown
On this page

Live preview needs WebGPU or WebGL 2. A row of eight project pictures with their titles on a pinned frame, which slides sideways as you scroll, the pictures bending with the speed.

This example failed to draw.

Scroll the page. The frame holds still while the row slides by; tab through the titles or swipe the row and the page follows.
Params of horizontal
style

bend bows each picture against the motion.

Usage

Put it on a row with overflow-x: auto (cards with images inside) on a sticky stage inside its section. start() registers horizontal, 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 horizontal
<div class="reel">
<p class="reel-title">
<span>Selected work</span>
Eight projects, 2019 to 2026
</p>
<ul
class="reel-row"
data-dio="horizontal"
aria-label="Selected work"
>
<li>
<a href="/atlas-of-ice">
<img
src="/media/work/atlas-of-ice.webp"
width="1200"
height="800"
/>
Atlas of Ice
</a>
</li>
<li>
<a href="/cyanotype">
<img
src="/media/work/cyanotype.webp"
width="1200"
height="800"
/>
Cyanotype
</a>
</li>
<li>
<a href="/hares-fur">
<img
src="/media/work/hares-fur.webp"
width="1200"
height="800"
/>
Hare’s Fur
</a>
</li>
<li>
<a href="/measure-of-the-sky">
<img
src="/media/work/measure-of-the-sky.webp"
width="1200"
height="800"
/>
Measure of the Sky
</a>
</li>
<li>
<a href="/outer-coast">
<img
src="/media/work/outer-coast.webp"
width="1200"
height="800"
/>
Outer Coast
</a>
</li>
<li>
<a href="/polar-night">
<img
src="/media/work/polar-night.webp"
width="1200"
height="800"
/>
Polar Night
</a>
</li>
<li>
<a href="/sea-steps">
<img
src="/media/work/sea-steps.webp"
width="1200"
height="800"
/>
Sea Steps
</a>
</li>
<li>
<a href="/tranquility">
<img
src="/media/work/tranquility.webp"
width="1200"
height="800"
/>
Tranquility
</a>
</li>
</ul>
</div>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.reel-row', 'horizontal', {
style: 'bend',
strength: 1,
stretch: 0.15,
parallax: 0.06,
pace: 1,
reverse: false,
ease: 0.3,
})
import { start } from '@dioramajs/diorama'
import horizontal from '@dioramajs/media/horizontal'
const app = start()
app.attach('.reel-row', horizontal({
style: 'bend',
strength: 1,
stretch: 0.15,
parallax: 0.06,
pace: 1,
reverse: false,
ease: 0.3,
}))

Markup it reads

  • img, video inside: Pictures inside the row (items): each gets a copy that bends; text, links and buttons stay DOM.

Page transitions

The copies of the pictures fade with the page transition; the row itself is the DOM. How a flight flies.

Params

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

ParamTypeDefaultDescription
stylerebuildsdata-dio-style'bend' | 'skew' | 'wave''bend'
  • bend bows each picture against the motion.
  • skew shears it, top leading.
  • wave sends one wave across the screen that the cards ride through.
strengthdata-dio-strengthnumber0 to 21How far the pictures bend, shear or wave at full speed; 0 keeps them flat.
stretchdata-dio-stretchnumber0 to 0.50.15Extra width at full speed, as a share of the card; 0 for none.
parallaxdata-dio-parallaxnumber0 to 0.20.06How far the picture drifts inside its card as it crosses the screen, as a share of the card; 0 for none.
pacedata-dio-pacenumber0 to 31Pixels of scroll per pixel the row travels: the effect sets the section height to fit. 0 keeps the height from your CSS.
reversedata-dio-reversebooleanfalseStarts the row at its end and moves it right.
easedata-dio-easenumber0 to 1 s0.3How long the pictures take to follow the speed and flatten again.
itemsrebuildsdata-dio-itemsstring'img, video'Pictures in the row that get a bending copy.

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 . Draws only while something on it moves, then stops. Scroll draws its own frames; ease keeps drawing until the pictures are flat. None at rest. How a frame is decided.

Reduced motion and touch

With reduced motion it is off and the element shows as plain HTML. Off: the row stays a plain horizontal scroller in a section of its own height, and the engine does not load for it.

Runs on every device. Scrolling the page moves the row, and a sideways swipe on the row scrolls it natively while the page follows.

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

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

Cost and quality

Download
2.0 KB min+gzip the first time a page uses it
GPU
One texture read per pixel of each picture, on a plane of 24 rows for bend and wave.
Memory
The textures of the pictures in the row.
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

Selected work, sideways

The portfolio and agency classic: a section whose stage sticks to the top, with a row of cards on it. The row is a plain horizontal scroller, overflow-x: auto, so it works before the engine loads, without WebGL and under reduced motion. Put data-dio="horizontal" on the row; the effect finds the sticky stage, gives the section the height the row needs to travel and moves the row as you scroll down.

<section>
<div class="stage">
<ul
class="row"
data-dio="horizontal"
aria-label="Selected work"
>
<li>
<a href="/work/atlas-of-ice">
<img src="/img/atlas-of-ice.avif" />Atlas of Ice
</a>
</li>
<li>
<a href="/work/outer-coast">
<img src="/img/outer-coast.avif" />Outer Coast
</a>
</li>
<!-- more cards -->
</ul>
</div>
</section>
.stage {
position: sticky;
top: 0;
height: 100vh;
display: grid;
align-content: center;
}
.row {
display: flex;
gap: 24px;
overflow-x: auto;
padding: 40px 6vw;
/* For the plain row; the effect turns it off while it runs. */
scroll-snap-type: x mandatory;
}
.row li { flex: none; scroll-snap-align: start; }
.row img { width: 30vw; aspect-ratio: 4 / 5; object-fit: cover; }

Do not set a height on the section: the effect makes it as tall as the stage plus the distance the row travels, so one pixel of scroll moves the row one pixel. pace="1.5" gives the row more scroll; pace="0" keeps the height from your CSS and spreads the travel over it.

Shear or a wave instead of a bend

style="skew" shears the pictures, top leading, the way fast motion looks on film. style="wave" sends one wave across the screen that the cards ride through.

<ul
class="row"
data-dio="horizontal"
data-dio-style="skew"
data-dio-stretch="0"
></ul>
<ul
class="row"
data-dio="horizontal"
data-dio-style="wave"
data-dio-reverse
></ul>

Calm pictures

The row still slides, but the pictures stay flat and still inside their cards: strength, stretch and parallax at 0.

<ul
class="row"
data-dio="horizontal"
data-dio-strength="0"
data-dio-stretch="0"
data-dio-parallax="0"
></ul>

Notes

The row stays a real scroller while the effect runs. Tabbing to a card brings it fully into view and scrolls the page to match; a sideways swipe or Shift with the wheel moves the row and the page follows. Only the pictures get a copy: titles, links and buttons are the DOM.

Leave some padding above and below the cards: the row clips them like the browser does, and a bend or a wave needs a little room.

Under reduced motion the effect is off: the row is a plain horizontal scroller in a section of its own height.

style and items rebuild the effect; strength, stretch, parallax, pace, reverse and ease change live.