# horizontal

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

While the section is pinned, scrolling down moves the row of cards to the left, one pixel sideways per pixel of scroll. The pictures bow like paper dragged through air, shear or ride a wave across the screen, stretch a little with the speed and settle when the scroll stops; inside each card the picture drifts slower than its frame. The row is a real horizontal scroller, so links, focus, arrow keys and swipes move it too, and the page follows.

Module `media`, category Scroll scenes. Import `@dioramajs/media/horizontal`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/media/src/horizontal.ts)

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.

```html title="index.html"
<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" alt="Snow-covered ridges under a pale sky" width="1200" height="800" />Atlas of Ice</a></li>
    <li><a href="/cyanotype"><img src="/media/work/cyanotype.webp" alt="A white seaweed print on deep blue paper" width="1200" height="800" />Cyanotype</a></li>
    <li><a href="/hares-fur"><img src="/media/work/hares-fur.webp" alt="A dark glazed tea bowl on a grey ground" 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" alt="A brass astrolabe with engraved scales" width="1200" height="800" />Measure of the Sky</a></li>
    <li><a href="/outer-coast"><img src="/media/work/outer-coast.webp" alt="Dark cliffs above a grey sea under clouds" width="1200" height="800" />Outer Coast</a></li>
    <li><a href="/polar-night"><img src="/media/work/polar-night.webp" alt="Green aurora over the curve of the Earth, seen from orbit" width="1200" height="800" />Polar Night</a></li>
    <li><a href="/sea-steps"><img src="/media/work/sea-steps.webp" alt="Concrete steps into a grey sea, a wave breaking behind them" width="1200" height="800" />Sea Steps</a></li>
    <li><a href="/tranquility"><img src="/media/work/tranquility.webp" alt="Boulders on grey lunar ground" width="1200" height="800" />Tranquility</a></li>
  </ul>
</div>
```

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

```html
<section><div style="position: sticky; top: 0; height: 100vh; display: grid; align-content: center"><ul style="display: flex; gap: 24px; overflow-x: auto; padding: 40px 6vw; margin: 0; list-style: none" data-dio="horizontal"><li><a href="/work/coast"><img src="/img/coast.avif" alt="Outer coast" style="width: 32vw; aspect-ratio: 3 / 4; object-fit: cover" /></a></li><li><a href="/work/ice"><img src="/img/ice.avif" alt="Sea ice" style="width: 32vw; aspect-ratio: 3 / 4; object-fit: cover" /></a></li></ul></div></section>
```

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

In page transitions: The copies of the pictures fade with the page transition; the row itself is the DOM.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-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. |
| `strength` | `data-dio-strength` | `number` 0 to 2 | `1` | How far the pictures bend, shear or wave at full speed; 0 keeps them flat. |
| `stretch` | `data-dio-stretch` | `number` 0 to 0.5 | `0.15` | Extra width at full speed, as a share of the card; 0 for none. |
| `parallax` | `data-dio-parallax` | `number` 0 to 0.2 | `0.06` | How far the picture drifts inside its card as it crosses the screen, as a share of the card; 0 for none. |
| `pace` | `data-dio-pace` | `number` 0 to 3 | `1` | Pixels of scroll per pixel the row travels: the effect sets the section height to fit. 0 keeps the height from your CSS. |
| `reverse` | `data-dio-reverse` | `boolean` | `false` | Starts the row at its end and moves it right. |
| `ease` | `data-dio-ease` | `number` 0 to 1 s | `0.3` | How long the pictures take to follow the speed and flatten again. |
| `items` (rebuilds) | `data-dio-items` | `string` | `'img, video'` | Pictures in the row that get a bending copy. |

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

### Variants

- `style`: `bend`, `skew`, `wave`
  - `bend` bows each picture against the motion.
  - `skew` shears it, top leading.
  - `wave` sends one wave across the screen that the cards ride through.

## Inputs and frames

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

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

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

start({ effects: { horizontal: { reducedMotion: 'static' } } })
```

## Cost and quality

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

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

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

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

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

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

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

## Related

- [curtain](/docs/effects/curtain.md): A cover picture opens from behind a curtain as you scroll: strips slide away, halves part or a liquid edge drains past.
- [expand](/docs/effects/expand.md): The image of a card grows to fill its sticky stage as the section scrolls.
- [sequence](/docs/effects/sequence.md): An image sequence scrubbed by scroll, frame by frame, from a poster <img>.
- [zoom-scroll](/docs/effects/zoom-scroll.md): A picture in a pinned section zooms from its box to fill the screen as you scroll.
- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [bend](/docs/effects/bend.md): Scroll speed bends the image like paper and splits its color channels.
- [blinds](/docs/effects/blinds.md): A heading printed across real 3D slats that turn over in a wave, lit and casting shadows, to show it.
- [book](/docs/effects/book.md): A cover image made a 3D book that turns to show its spine and opens on hover.
- [How a layer follows scroll](/docs/concepts/scroll.md)
- [GSAP and Lenis](/docs/guides/gsap-lenis.md)
