Searching Puzzle Pieces

Type to search Puzzle Pieces.

Scroll Stack

A natively scrolling list whose items animate at the scrollport edges instead of clipping. The exiting item stops dead at the boundary, fades and shrinks in place, and the next one slides over it. No scroll hijacking — the browser scrolls, the component only reads.

This piece is a wrapper, not a port: it renders the real <scroll-stack> custom element from @magic-spells/scroll-stack and binds attributes to it. Every effect is a CSS rule keyed off a progress custom property the engine writes, so the component is fully restylable from outside — there is no behavior worth reimplementing, and the measurement code is subtle enough that forking it would be a liability.

Every live example on this page runs with snap on, so each list comes to rest on an item boundary rather than mid-fade. It is off by default, and it is mandatory — see Snap carousel.

Edge

Threshold

The band where an item stops being fully visible and starts being a number.

Math

Overshoot

How far past the edge the item has travelled, normalized against the zone.

Sticky

Handoff

The moment the pinned card stops moving and the next one takes the frame.

Math

Damping

An edge you cannot scroll past never animates the item resting against it.

Writes

Quantize

A thousandth of progress is the smallest change worth a style write.

Frames

Coalesce

Every scroll burst, resize and mutation collapses into one animation frame.

Effect

Origin

Scaling content pulls away from the clip boundary instead of being sliced by it.

Rest

Settle

Nothing is scheduled while the list is at rest — the loop is genuinely idle.

Installation

Copy the piece into your app — it compiles with your build and the code is yours:

puzzle add piece scroll-stack

This one has a runtime dependency: the web component it wraps.

npm install @magic-spells/scroll-stack

Then merge the component's stylesheet into your app's style entry (app/styles/styles.css). It is where the effects, the pinning, the snapping and the per-view sizing actually live, so the piece does nothing without it:

/* app/styles/styles.css */
@import "tailwindcss";
@import "@magic-spells/scroll-stack/css" layer(components);

The layer(components) part is not decoration. The component styles itself with plain element selectors, and an unlayered import outranks every Tailwind utility — gap-4 or rounded-xl on the element would silently do nothing. In the components layer the normal mental model holds: your utilities win, the component's defaults fill in the rest.

Requires the pieces.css tokens merged into your app styles (see Introduction).

Usage

import ScrollStack from '@/components/ui/ScrollStack.pzl';
<ScrollStack class="h-96 rounded-xl border border-border" snap={ true } gap="0.75rem">
  <scroll-stack-item>
    <div class="rounded-lg bg-surface-sunken p-4">One</div>
  </scroll-stack-item>
  <scroll-stack-item>
    <div class="rounded-lg bg-surface-sunken p-4">Two</div>
  </scroll-stack-item>
</ScrollStack>

Item markup contract

Children are parent-authored and pass through the default slot untouched, so you write the item elements yourself. Three rules:

  • Every child is a <scroll-stack-item>. It is the layout and pinning box, and it carries the progress custom properties.
  • Every item needs exactly one element child. That child is what the effect applies to — the wrapper pins while the content fades and scales, so neither fights the other. An item with no element child is skipped with one console warning.
  • Style the inner element, not the item. Padding, background, borders and rounding all belong on the child; the item should stay a bare box.
  • No scroll-axis margins on that child. The pin travels in percentages of the content box. The component stretches the content to fill the item box and zeroes its margins along the scroll axis (margin-block vertically, margin-inline horizontally) — cross-axis margins like mx-auto are left alone. That reset is only element-selector strength, though, so a Tailwind my-* on a vertical list's content still wins and desynchronises the pin by that many pixels per item. Use the gap prop for spacing between items.

One thing to avoid: a dynamic style={ … } binding on an item. The patcher rewrites the whole style attribute and would clobber the per-frame custom-property writes — the same rule that applies to morph elements. A static style string is fine.

Sizing note: perView resolves to a flex-basis on the item, which beats any width you put on it. Size the content element instead, or drop the sizing props.

Horizontal + per-view sizing

01Threshold
02Overshoot
03Handoff
04Damping
05Quantize
06Coalesce
07Origin
08Settle

The tiles carry no width of their own. Resize the window and the count changes: the engine fits as many whole items as still clear itemMin, divides the remainder evenly, and publishes the result as a custom property that drives each item's flex-basis.

Snap carousel

Threshold
Overshoot
Handoff
Damping
Quantize
Coalesce
Origin
Settle

snap is native CSS scroll snapping — two declarations, no JavaScript. The one thing the engine does differently while snapping is drop the scroll-padding it normally writes: padding shifts every snap position, and a snapped item is fully visible anyway. Pass snap="center" to snap item centers instead of their leading edges.

Bare snap and snap="center" are mandatory. They can be because items are plain flow boxes whose snap areas never move — while the pin was position: sticky a stuck item's snap area tracked the scroll offset and mandatory truncated every fling. snap="proximity" is the softer opt-out.

This example also fixes the count — perView=3 divides the port three ways instead of fitting as many as clear the minimum — and uses effect="fade-scale", which is the default's visuals without the pinning.

Pin both edges — a deck

Edge

Threshold

Math

Overshoot

Sticky

Handoff

Math

Damping

Writes

Quantize

Frames

Coalesce

Effect

Origin

Rest

Settle

pin decides stickiness; effect only decides pixels. With pin="both" each item is pinned at the top and the bottom, so the next card waits pinned at the bottom edge, fading up as it is dealt, while the spent one pins at the top and recedes. Omit pin and the effect implies one — stack-fade pins at the start edge, everything else pins nothing.

Custom effect from the progress variable

Edge

Threshold

Math

Overshoot

Sticky

Handoff

Math

Damping

Writes

Quantize

Frames

Coalesce

Effect

Origin

Rest

Settle

With effect="none" the component ships no visuals at all — it only publishes --scroll-stack-progress (eased 0 → 1) and --scroll-stack-edge (-1 at the start edge, 1 at the end, 0 in between). Everything above is arbitrary-value Tailwind reading those two numbers. There is no plugin API because there is nothing a plugin API could do that calc() cannot.

Reference

Every prop maps to an attribute on the element. A prop you don't pass renders no attribute at all, so the component's own default applies.

Props

direction'vertical' (default) | 'horizontal' — the scroll axis. The progress math is direction-agnostic; everything else behaves identically.
effect'stack-fade' (default) | 'fade-scale' | 'fade' | 'scale' | 'none'. Selects a block of CSS and nothing more — 'none' publishes the variables and ships no visuals.
pin'start' | 'end' | 'both' | 'none' — which edges hold an item still while its flow position keeps moving. Omit it and the effect implies one: stack-fade → start, everything else → none.
zone'item' (default) | '<n>px' | '<n>%' — how deep the animation band reaches in from an edge. Capped at 45% of the scrollport so the two bands can never overlap.
edges'both' (default) | 'start' | 'end' — which scrollport edges animate at all.
snapNative CSS scroll snapping. true snaps item starts to the edge and 'center' snaps their centers — both MANDATORY, which is safe because items are plain flow boxes. 'proximity' is the softer opt-out, start-aligned.
perViewA positive integer, or 'auto' to fit as many whole items as clear itemMin. Resolves to each item's flex-basis, so it works on either axis.
itemMinCSS length (px, rem, % of the scrollport — a bare number means px). Floor for the resolved item length, and the input to the auto count.
itemMaxCSS length. Ceiling for the resolved item length; when it is smaller than the fitted slot the row stops filling the port exactly.
easing'linear' (default) | 'ease-in' | 'ease-out' | 'ease-in-out' — applied to progress before it is written.
reducedMotion'auto' (default) | 'ignore'. Under prefers-reduced-motion transforms are dropped and fades are kept; 'ignore' opts the list out.
disabledZeroes every variable, drops the state attributes, and detaches the engine — the list becomes a plain scroller.
gapCSS length written as --scroll-stack-gap. Tailwind gap-* utilities work too.
classMerged onto the element. This is where the height (or width) that makes it a scroller goes.
styleAppended after the gap declaration — for setting the other custom properties inline.

Custom properties

--scroll-stack-gapSpace between items. Default 0; also settable with the gap prop or a Tailwind gap utility.
--scroll-stack-shrinkHow far the built-in scale effects shrink at full progress. Default 0.15.
--scroll-stack-progressRead-only, written on each item: eased progress from 0 (fully in view) to 1 (fully faded), quantized to a thousandth.
--scroll-stack-edgeRead-only, written on each item: -1 at the start edge, 1 at the end edge, 0 anywhere in between.
--scroll-stack-item-lengthRead-only, written on the element when perView / itemMin / itemMax are in play: the resolved slot length in px.

Events

The element dispatches these itself and they bubble, so listen on any ancestor. They fire on state change only, never per frame.

scroll-stack:item-hiddenAn item reached full progress. detail: { item, index, edge }.
scroll-stack:item-shownAn item left full progress. detail: { item, index, edge }.