# Hover Craft

https://docs.kleaver.ie/sfx/cardstack/

SFX

# Hover Craft

A list of steps whose cards slide up and stack over one another as you scroll, so a step-by-step feels like something happening instead of a column to skim. This first demo is the **grouped** variant: each step's title, text and card travel together. Scroll to see them stack.

## Rail

The titles stay in a rail beside the cards, so you can see how many steps there are and which one you are on. Below 800px it becomes the grouped variant. Pressing Enter on a title brings its step up.

## Markup

Put class="cardstack" and data-cardstack on a container, and data-cardstack-step on each step inside it (direct children). Mark each title with data-cardstack-title; the rail is built from them.

```
<div class="cardstack" data-cardstack="rail">
  <section data-cardstack-step>
    <h3 data-cardstack-title>Pick a look</h3>
    <p>…</p>
  </section>
  <section data-cardstack-step> … </section>
</div>

<script defer src="scripts/cardstack.js"></script>   <!-- only on pages that use it -->
```

## Attributes

| Attribute | On | Values |
| --- | --- | --- |
| data-cardstack | the container | rail (default) · grouped |
| data-cardstack-step | each step | a direct child of the container; the step is the card |
| data-cardstack-title | the title inside a step | its text becomes the rail entry (else "Step N") |

The script adds data-cardstack-ready to the container, and --i, an id and data-state (buried · active · upcoming) to each step. It also sends cardstack:set to the container with detail { variant } to switch variant.

## Tokens

The look is a token, set in the client's theme.css. For no pile, set the peek to 0.

| Token | Default | What it does |
| --- | --- | --- |
| --cardstack-peek | 12px | How much of each buried card's top edge shows. 0 = the cards cover each other completely: no pile. |
| --cardstack-offset | var(--space-6) | Where the stack sticks, from the top of the viewport. Raise it to clear a sticky header. |
| --cardstack-gap | var(--space-6) | Space between the cards before they stack. |
| --cardstack-dim | 0.92 | Brightness of a buried card. 1 = not dimmed. |
| --cardstack-scale | 1 | Size of a buried card. 0.97 = slightly smaller. |
| --cardstack-rail-width | 14rem | Width of the title rail. |

## Behaviour and limits

- **Opt-in.** A site whose pages have no .cardstack gets none of its CSS or JavaScript. The script is not part of the shared bundle.
- **Plain list when it cannot run.** Without JavaScript, with reduced motion, or for a card taller than the viewport, the steps are an ordinary list and nothing is hidden.
- **It is only sticky positioning.** The page always scrolls at its normal speed; nothing is scroll-jacked.
- **An ancestor with overflow other than visible breaks it.** Sticky cannot work inside a clipped or scrolling parent. The console warns once if it finds one.
- **A sticky header needs room.** Set --cardstack-offset to the header's height plus a little.
- **Keep the cards shorter than the screen.** The step is the card and it sticks whole, so a tall one is better left to scroll normally (it does, automatically).
- **Accessibility.** The steps stay in reading order in the page. The rail is navigation to them, and the current step is marked aria-current="step".

## Catalog

Hover Craft (in `components.css`)  ·  SFX #3  ·  see **`cardstack.html`**

| Component | Markup | Use for |
|---|---|---|
| Hover Craft | `<div class="cardstack" data-cardstack="rail\|grouped">` > `[data-cardstack-step]` (direct children; each holds a `[data-cardstack-title]` and the card's content) | A step-by-step (how it works, the process, an onboarding) where each card slides up over the one before as you scroll. Two variants: `rail` (the titles stay in a rail beside the cards, so the visitor sees how many steps there are and where they are) and `grouped` (each title travels with its card). |

- **Attributes:** `data-cardstack` = `rail` (default) or `grouped` on the container; `data-cardstack-step` on each step (the step *is* the card); `data-cardstack-title` on the title inside it (its text becomes the rail entry).
- **Tokens** (in `theme.css`): `--cardstack-peek` (how much of each buried card's top edge shows; **`0` = no pile**, the cards cover each other completely), `--cardstack-offset`, `--cardstack-gap`, `--cardstack-dim`, `--cardstack-scale`, `--cardstack-rail-width` (see `THEMING.md`).
- **Script:** `<script defer src="scripts/cardstack.js"></script>` on the page. The motion is CSS (`position: sticky`); the script marks the container `data-cardstack-ready` (the CSS does nothing until then), numbers the steps (`--i`), tracks the active step (`data-state` = `buried` / `active` / `upcoming`, `aria-current="step"`) and builds the rail.
- **Rules:** the steps must be direct children. An ancestor with `overflow` other than `visible` breaks sticky (the console warns once). A card taller than the viewport stops sticking so its end can be reached. A sticky header needs `--cardstack-offset` raised to clear it. Below 800px `rail` becomes `grouped`.
- **Accessibility:** no JavaScript, reduced motion or a failed script = a plain list, nothing hidden. The steps stay in reading order; the rail is navigation to them (anchors to the step ids).
- **Event:** `cardstack:set` on the container with `detail { variant? }` switches the variant and re-measures (send it after changing a token from script; the docs panel uses it).
- **Tuning:** `cardstack.html` has a live panel (pile on/off, peek, dim, scale); **Copy tokens** gives the CSS for `theme.css`.
