Scroll Fade
Utilities for scroll-aware fading at the edges of overflow containers.
Loading preview…
1<script lang="ts">
2 import { scrollFadeClass, scrollFadeXClass } from "./scroll-fade.js";
3 const items = Array.from({length: 12}, (_, i) => `Item ${i + 1}`);
4 const tags = ["Design", "Engineering", "Marketing", "Product", "Research", "Sales", "Support", "Operations"];
5</script>
6
7<div class="flex w-full max-w-md flex-col gap-6">
8 <div class="overflow-hidden rounded-xl border">
9 <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
10 <div class={`${scrollFadeClass} max-h-40 px-4 py-2`} tabindex="0" role="region" aria-label="Scrollable items">
11 <ul class="divide-y">{#each items as item (item)}<li class="py-2 text-sm">{item}</li>{/each}</ul>
12 </div>
13 </div>
14 <div class="overflow-hidden rounded-xl border">
15 <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
16 <div class={`${scrollFadeXClass} flex gap-2 px-3 py-3`} tabindex="0" role="region" aria-label="Scrollable teams">
17 {#each tags as tag (tag)}<span class="shrink-0 rounded-full border bg-muted px-3 py-1 text-xs font-medium">{tag}</span>{/each}
18 </div>
19 </div>
20</div>
21Installation
1. Install dependencies
Usage
These class helpers use the utilities shipped in shadcn-svelte/tailwind.css. The design system Styles already imports them. In other projects, add this once to your global CSS:
1@import "tailwindcss";
2@import "shadcn-svelte/tailwind.css"; 1<script lang="ts">
2 import { scrollFadeClass } from "~/lib/scroll-fade";
3</script>
4
5<div class="overflow-hidden rounded-xl border">
6 <div class={`${scrollFadeClass} max-h-48`}>
7 <!-- Scrollable content -->
8 </div>
9</div> Put borders and backgrounds on an outer wrapper so the mask only fades the content. Class helpers include overflow behavior; direct CSS classes can also be used in markup.
| Class | Effect |
|---|---|
scroll-fade / scroll-fade-y | Fade vertical edges |
scroll-fade-x | Fade horizontal edges |
scroll-fade-t, -b, -l, -r | Fade a physical edge |
scroll-fade-s, -e | Fade logical inline edges, including RTL |
scroll-fade-<n> | Set fade depth using the spacing scale |
scroll-fade-none | Disable fading |
Exports include scrollFadeClass, scrollFadeYClass, scrollFadeXClass, scrollFadeEdgeClasses, scrollFadeSizeClasses, and scrollFadeNoneClass. Helpers contain complete literal class names that Tailwind can detect. Browsers with scroll timelines reveal fades as content scrolls; browsers without them use static edge masks.