# Scroll fade

A utility class that fades the edge of a scrolling area to show there is more beyond it.

This is the HTML to build it with `dex.css`, for work outside the Dex codebase. Read https://brand.meetdex.ai/design.md first: it says how to set up a page and how to use the stylesheet. The page at https://brand.meetdex.ai/components/scroll-fade shows the Dex app's own utility classes, which only work inside the Dex codebase.

## HTML

`dex.css` has no scroll fade. The tokens `--dex-fade-x` and `--dex-fade-y` fade both ends by 28%, which is right for a divider but far too deep for a scroller, so don't use them here. Instead, put a mask of your own on the element that scrolls, and a few lines of script that fade an edge only while there's more beyond it:

```html
<style>
  .fade-y {
    --top: 0px;
    --bottom: 0px;
    mask-image: linear-gradient(to bottom, transparent, #000 var(--top), #000 calc(100% - var(--bottom)), transparent);
  }
</style>

<ul class="fade-y" style="max-height: 12rem; overflow-y: auto; margin: 0; padding: 1rem; list-style: none">
  <li class="dex-small" style="padding: 0.5rem 0">Staff software engineer, QuantumLeap</li>
  <li class="dex-small" style="padding: 0.5rem 0">Senior backend engineer, Synthesia</li>
  <!-- more rows -->
</ul>

<script>
  document.querySelectorAll('.fade-y').forEach((list) => {
    const update = () => {
      const more = list.scrollHeight - list.clientHeight - list.scrollTop
      list.style.setProperty('--top', list.scrollTop > 1 ? '2.5rem' : '0px')
      list.style.setProperty('--bottom', more > 1 ? '2.5rem' : '0px')
    }
    list.addEventListener('scroll', update, { passive: true })
    update()
  })
</script>
```

- **Horizontal**: the same with `to right`, `scrollLeft`, `scrollWidth` and `clientWidth`, for a row of chips.
- **One edge**: set only `--top` or `--bottom`, for a scroller with something fixed against its other edge, such as a header or a footer.
- **Depth**: 2.5rem (40px) is the app's deepest; use less on a short scroller.

## Rules

- The fade is a mask on the scrolling element, not a gradient laid over it, so the content dissolves into whatever is behind and nothing covers it.
- An edge fades only while there's more beyond it. A list short enough to fit doesn't fade at all.
- The app uses it on the chat's message list (top and bottom), its row of quick replies (both ends) and a table wider than its card (the cut-off edge).
