Scroll Stack
A natively scrolling list whose items animate at the scrollport edges instead of clipping — the exiting one stops dead at the boundary and fades while the next slides over it.
v0.1.0@magic-spells/scroll-stack
Live demo
Scroll natively
It is a real overflow container — wheel, touch, keyboard and scrollbars all work as usual.
Nothing clips
The card leaving the top stops at the edge and fades out instead of being cut off.
The next slides over
The one behind it moves up and covers it as you keep scrolling.
Rest on a card
With snap on, a scroll settles with a whole card at the top.
Reduced motion
With prefers-reduced-motion set, the edge animations switch off.
Just items
Each child is a scroll-stack-item. There is no configuration beyond attributes.
Scroll the list: the leaving card stops at the edge and fades while the next slides over it.
About
A natively scrolling list web component 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 item slides over it; entering items animate in from the far edge. Vertical or horizontal, with mandatory scroll snapping and responsive per-view item sizing, and every effect is plain CSS driven by one custom property. 3.5 kB JS gzip, 0.9 kB CSS gzip, zero dependencies, no Shadow DOM.
Usage
<scroll-stack style="height: 26rem"> <scroll-stack-item> <article class="card">First</article> </scroll-stack-item> <scroll-stack-item> <article class="card">Second</article> </scroll-stack-item> </scroll-stack>
Attributes
| Attribute | Values | Default | Notes |
|---|---|---|---|
| direction | vertical | horizontal | vertical | Sets the scroll axis |
| effect | stack-fade | fade-scale | fade | scale | none | stack-fade | Selects a block of CSS; none publishes the vars and nothing else |
| pin | start | end | both | none | see below | Which edges hold an item still while its flow position moves on |
| zone | item | px | % | item | Depth of the animation band; capped at 45% of the scrollport |
| edges | both | start | end | both | Which edges animate at all |
| snap | boolean | start | center | proximity | off | Scroll snapping; presence alone means mandatory start |
| per-view | positive integer | auto | unset | How many items fill the scrollport |
| item-min | CSS length (px, rem, %) | unset | Floor for the resolved item length |
| item-max | CSS length (px, rem, %) | unset | Ceiling for the resolved item length |
| easing | linear | ease-in | ease-out | ease-in-out | linear | Applied to progress before it is written |
| reduced-motion | auto | ignore | auto | ignore opts out of the reduced-motion override |
| disabled | boolean | off | Removes every var and state attribute, detaches all listeners |
About, features, usage and options are taken from the package README.