A CSS-only carousel drawn as a cover flow

The carousel below is a list with scroll-snap-type, ::scroll-button() and ::scroll-marker. No script scrolls it. It's a child of a canvas, and the canvas draws each slide as its own textured quad, placed by how far the slide is from the centre of the scroller. Swipe it, use the two buttons or the dots (they are the generated pseudo-elements, drawn by the canvas), or tab through the Save buttons.

  • 01

    Crimson

    Hue 0. The first slide of the list.

  • 02

    Amber

    Hue 45, from sibling-index().

  • 03

    Lime

    Hue 90. Each slide is one texture.

  • 04

    Jade

    Hue 135. The button is a real button.

  • 05

    Teal

    Hue 180. Tab to it and the list scrolls.

  • 06

    Azure

    Hue 225. Snapping is the scroller's.

  • 07

    Violet

    Hue 270. The frame comes from scroll-state().

  • 08

    Rose

    Hue 315. The last slide of the list.

 

The results are in the Live checks table below.

Show the code CSS carousel, one texture per slide, one matrix per slide
  1. The list is inside the canvas. The deck is a drawable child, and each slide inside the scroller is drawable too.
  2. The carousel is CSS. Scroll snap, ::scroll-button(), ::scroll-marker, a scroll-state(snapped) query and sibling-index().
  3. Where a slide goes. Its distance from the centre of the scroller, in slides, gives a position and a rotation.
  4. The matrix for one card. CSS pixels of the card to CSS pixels of the canvas, with perspective, then to clip space.
  5. Hit boxes. One place for every card; CSS decides which card's button is live.
  6. On paint. Upload the elements that changed, draw the deck, then the slides from the farthest to the nearest.
  7. The fragment shader. Edge smoothing, shading by tilt, a moving highlight on the centred slide, and the fade of the reflection.
  8. The upload. texElementSubImage2D() into a texture of exactly the element's picture size.

How it works

The scroller holds eight empty list items with scroll-snap-align; they're the snap stops and they generate the dots. Each item contains a card that is drawable and positioned against the deck, so it doesn't scroll and isn't clipped. The canvas uploads each card as its own texture and, on every paint event, draws the cards as quads whose position and rotation come from scrollLeft. The deck's own picture (background, the two buttons, the dots) is drawn first on a full-size quad. The canvas repaints on scroll, when a card's picture changes, and for one second after a snap.

Live checks

The button under the demo runs these. They use the demo itself, so it has to be on screen: a point outside the window can't be hit tested.

CheckResultDetail
Every slide inside the scroller has its own texturenot run
The deck's picture does not contain the slidesnot run
The Save button of the centred card takes a tap, and the button of a side card does notnot run
The scroll-state(snapped) query styles the centred cardnot run
The current ::scroll-marker is the centred slide'snot run

Findings