Scroll Fade
There's more where that came from. Utilities that fade the edges of a scroll region while there's more to scroll that way.
Message 1
Message 2
Message 3
Message 4
Message 5
Message 6
Message 7
Message 8
Message 9
Message 10
Message 11
Message 12
Message 13
Message 14
Message 15
Message 16
Message 17
Message 18
Message 19
Message 20
Message 21
Message 22
Message 23
Message 24
Message 25
Message 26
Message 27
Message 28
Message 29
Message 30
Installation
Adds @import "@kappa-ui/core/tailwind.css"; and the tokens it reads to your global stylesheet, once, even if other components need them too.
Mask or overlay?
scroll-fade (mask) | scroll-fade-overlay | |
|---|---|---|
| How it fades | content turns transparent | a gradient covers the edge |
| Background | anything, even an image | one plain colour |
| While scrolling | repaints near an edge, can lag on long lists | free |
| On a ScrollArea | doesn't work | works |
Short version: use the overlay by default. Reach for the mask only when the background isn't a plain colour.
Usage
<script setup lang="ts">
import { vScrollFade } from "@kappa-ui/core/scroll-fade";
</script>
<!-- mask: on the scroll container itself -->
<div v-scroll-fade class="scroll-fade overflow-y-auto">…</div>
<!-- overlay: on a wrapper around the scroll container -->
<div class="scroll-fade-overlay overflow-hidden">
<div v-scroll-fade class="h-full overflow-y-auto">…</div>
</div>
<!-- overlay on a scroll area: no directive needed -->
<ScrollArea orientation="horizontal" class="scroll-fade-overlay-x">…</ScrollArea>
Always put v-scroll-fade on the scroll container. Without it, Firefox keeps both edges faded.
Overlay
Horizontal
scroll-fade-x fades left and right, flipping for right-to-left pages.
Customizing
Depth. scroll-fade-8 or scroll-fade-[40px] sets how deep the fade goes, in both modes. In mask mode, each edge can have its own: scroll-fade-t-4 scroll-fade-b-12.
Colour. The overlay fades into --scroll-fade-color, the page background by default. Cards, dialogs, menus, popovers and other surfaces of the kit set it for you. On a surface of your own, set it to match:
<div class="scroll-fade-overlay overflow-hidden bg-muted [--scroll-fade-color:var(--muted)]">
<div v-scroll-fade class="h-full overflow-y-auto">…</div>
</div>
Edges. -y for top and bottom (the default), -x for left and right, or one edge: -t, -b, -s, -e. Use -none to turn the fade off, for example md:scroll-fade-none.
Speed. --scroll-fade-reveal sets how far you scroll before an edge fully fades in.
Firefox
Firefox can't tell how far a region has scrolled with CSS alone yet. v-scroll-fade fills the gap there and does nothing in other browsers. Open this page in Firefox to compare:
Message 1
Message 2
Message 3
Message 4
Message 5
Message 6
Message 7
Message 8
Message 9
Message 10
Message 11
Message 12
Message 13
Message 14
Message 15
Message 16
Message 17
Message 18
Message 19
Message 20
Message 1
Message 2
Message 3
Message 4
Message 5
Message 6
Message 7
Message 8
Message 9
Message 10
Message 11
Message 12
Message 13
Message 14
Message 15
Message 16
Message 17
Message 18
Message 19
Message 20
Reference
| Class | Mode | Edges |
|---|---|---|
scroll-fade, scroll-fade-y | mask | top and bottom |
scroll-fade-x | mask | start and end |
scroll-fade-t, -b, -l, -r, -s, -e | mask | one edge; s and e follow the reading direction |
scroll-fade-<n>, scroll-fade-[<length>] | both | fade depth |
scroll-fade-t-<n>, -b-<n>, -s-<n>, -e-<n> | mask | depth of one edge |
scroll-fade-none | mask | removes the mask |
scroll-fade-overlay, scroll-fade-overlay-y | overlay | top and bottom |
scroll-fade-overlay-x | overlay | start and end |
scroll-fade-overlay-s, -e, -t, -b | overlay | one edge |
scroll-fade-overlay-none | overlay | removes both overlays |
| Variable | Default | Description |
|---|---|---|
| --scroll-fade-size | min(12%, calc(var(--spacing) * 10)) | Depth of the fade, for both modes. |
| --scroll-fade-t-size | --scroll-fade-size | Depth of one edge in mask mode; also -b-, -s-, -e-. |
| --scroll-fade-reveal | calc(var(--spacing) * 24) | Scroll distance over which an edge fades in or out. |
| --scroll-fade-color | var(--background) | Colour the overlay gradients run to. Kit surfaces set it to their own background. |
Changelog
No changes yet.