coverflow
A row of covers as the classic cover flow: the middle one faces you, its neighbours turn away in perspective.
Live preview needs WebGPU or WebGL 2. Eight project covers in a row; the middle one faces you, its neighbors turn away, mirrored on the floor; drag, swipe or use the arrow keys.
This example failed to draw.
Usage
Put it on a list of linked images, such as albums, books, products or case studies. start() registers coverflow, 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.
npx @dioramajs/diorama add coverflow<ul class="work" data-dio="coverflow" data-dio-index="3" data-dio-reflection="0.25" aria-label="Eight projects. Drag, swipe or use the arrow keys; the cover in the middle opens its project." 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>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.work', 'coverflow', { style: 'classic', angle: 60, spacing: 0.3, depth: 0.6, shade: 0.4, reflection: 0.25, perspective: 900, duration: 0.5, loop: false,})import { start } from '@dioramajs/diorama'import coverflow from '@dioramajs/media/coverflow'
const app = start()app.attach('.work', coverflow({ style: 'classic', angle: 60, spacing: 0.3, depth: 0.6, shade: 0.4, reflection: 0.25, perspective: 900, duration: 0.5, loop: false,}))Events
It dispatches these on its element; they bubble.
dio:index,detail: { index: number }. A cover reached the middle after a move; index is its place among the images, from 0. Bubbles.dio:open,detail: { index: number }. The middle cover was clicked and its image is in no link or button; index is its place. Bubbles.
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.
| Param | Type | Default | Description |
|---|---|---|---|
indexdata-dio-index | number0 to 10 | 0 | Cover in the middle from 0; a fraction holds the row between two covers, for a tween. |
stylerebuildsdata-dio-style | 'classic' | 'arc' | 'cards' | 'classic' |
|
angledata-dio-angle | number0 to 80° | 60 | Turn of the side covers in classic, and of the cards behind; 0 lays them flat. |
spacingdata-dio-spacing | number0.05 to 1 | 0.3 | Gap between side covers, in widths of a cover. |
depthdata-dio-depth | number0 to 2 | 0.6 | How far the side covers step back, in widths of a cover; 0 keeps them level. |
shadedata-dio-shade | number0 to 1 | 0.4 | Darkening of the side covers, 0 for none. |
reflectiondata-dio-reflection | number0 to 1 | 0 | Opacity of the covers mirrored on the floor below them, 0 for none.At most low 0 by quality tier. |
perspectivedata-dio-perspective | number300 to 3000 px | 900 | Distance of the eye from the row, like CSS perspective; lower is stronger. |
durationdata-dio-duration | number0.15 to 2 s | 0.5 | Length of a move by one cover. |
loopdata-dio-loop | boolean | false | Goes round: after the last cover comes the first. |
dragdata-dio-drag | boolean | true | A drag or a swipe carries the row. |
wheeldata-dio-wheel | boolean | true | A sideways wheel or trackpad swipe moves the row. |
clickdata-dio-click | boolean | true | A click on a side cover brings it to the middle. |
itemsrebuildsdata-dio-items | string | '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. Only while the row moves; 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. Covers change at once: no glide, and a drag lands on its cover without coasting. Keys, clicks and swipes still move the row.
Runs on every device. A swipe moves the row. With touch-action: pan-y on the list the row follows the finger; without it the browser scrolls the list sideways and the row follows that scroll. A tap on a side cover brings it to the middle, on the middle one follows its link.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { coverflow: { reducedMotion: 'off' } } })Cost and quality
- Download
- 7.2 KB min+gzip the first time a page uses it
- GPU
- A quad per cover in reach, up to fifteen, one texture read per pixel; the reflection doubles the pixels of each cover.
- Memory
- The pictures of the covers in reach and one more on each side.
- Frames
- Idle at rest
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | No reflection. |
Recipes
Books stacked as cards
The cards style puts the covers behind the middle one, a little to the side and smaller, like a hand of cards: it fits a short shelf of books or products in a narrow box. With loop the row goes round, so the last book leads back to the first.
<ul class="shelf" data-dio="coverflow" data-dio-style="cards" data-dio-loop="true" data-dio-index="1" aria-label="Three books. Click, swipe or use the arrow keys for the next one." style="touch-action: pan-y"> <li> <a href="/blue-shore"> <img src="/media/books/blue-shore.webp" width="900" height="1350" /> </a> </li> <li> <a href="/low-water"> <img src="/media/books/low-water.webp" width="900" height="1350" /> </a> </li> <li> <a href="/salt-garden"> <img src="/media/books/salt-garden.webp" width="900" height="1350" /> </a> </li></ul><p class="shelf-title" aria-live="polite">Low Water</p>// The title of the book in the middle, from the part of its alt text before " by".export default function mount(example: HTMLElement): () => void { const shelf = example.querySelector('.shelf') const title = example.querySelector('.shelf-title') if (!shelf || !title) return () => {} const names = [...shelf.querySelectorAll('img')].map( (img) => img.alt.split(' by ')[0] ?? '', ) const onIndex = (e: Event) => { title.textContent = names[(e as CustomEvent<{ index: number }>).detail.index] ?? '' } shelf.addEventListener('dio:index', onIndex) return () => shelf.removeEventListener('dio:index', onIndex)}Name the cover in the middle
Nothing tells a screen reader that another cover reached the middle. Put a caption with aria-live="polite" next to the row and fill it from dio:index, whose index is the place of the cover among the images, from 0. The books above name their title this way.
const shelf = document.querySelector('.shelf')const title = document.querySelector('.shelf-title')const names = [...shelf.querySelectorAll('img')].map( (img) => img.alt.split(' by ')[0],)
shelf.addEventListener('dio:index', (e) => { title.textContent = names[e.detail.index]})Buttons for the next and the previous cover
Set index on the instance; the row glides there in duration per cover.
const row = document.querySelector('.work')
document.querySelector('.next').addEventListener('click', () => { const flow = app.effects.get(row, 'coverflow') flow?.set({ index: Math.round(flow.params.index) + 1 })})Notes
Write the row as a list of links around images, styled as the row you want without WebGL: a strip that scrolls sideways. Each cover takes the size of its image in that strip and stands at its height, so books of different heights keep their line, 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 covers to the sides and the reflection reach past the box of the list: leave room under it for the reflection, about half the height of a cover.
The copy hides the list, its background included, so put a background on a parent. A click on a drawn cover is caught by the effect, since the link under the pointer in the hidden list is another one: a click on a side cover brings it to the middle, a click on the middle one follows its link, with Ctrl or Cmd in a new tab. An image without a link fires dio:open instead, for a page that opens its own viewer.
The links stay in the page in order, each with its image’s alt text. Tab moves through them and the row follows the focused one; the arrow keys, PageUp, PageDown, Home and End move the row and the focus with it, and Enter opens the cover in the middle. Without links give the list tabindex="0" and an aria-label that says how to move on.
A drag with a mouse always carries the row. On touch screens set touch-action: pan-y on the list so the row follows the finger while the page still scrolls up and down; without it the browser scrolls the hidden list itself and the row follows that scroll. A wheel turned up and down always scrolls the page; only a sideways wheel or a two-finger swipe on a trackpad moves the row.
style and items rebuild the effect when they change. Set them in the markup rather than switching them while the row is on screen.










