Components Navigation & Shell ScrollShadows
ScrollShadows
Automatically cast edge shadows that fade in and out to indicate scrollable overflow.
Live demo
01Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
Item 15
Implementation
02 ScrollShadows.svelte
β
import ScrollShadows from '$lib/components/ScrollShadows.svelte';
β
<ScrollShadows direction="vertical" shadowSize="40px">
<div class="content-list">...</div>
</ScrollShadows>Logic explainer
03What Does It Do? (Plain English)
Automatically casts a smooth shadow at the edges of a scrollable container to indicate that there is more content overflowing. The shadow fades in when you can scroll and fades out when you reach the edge.
How It Works (Pseudo-Code)
IF CSS scroll-timeline is supported:
Use CSS to bind the opacity of the top/bottom shadows to the scroll position of the container.
ELSE:
Use the classic `background-attachment: local` trick to simulate scroll shadows.State Flow Diagram
stateDiagram-v2
[*] --> CheckSupport
CheckSupport --> ModernScrollTimeline : Supported
CheckSupport --> FallbackBackground : Not Supported
state ModernScrollTimeline {
ScrollTop --> FadeTopShadowIn
ScrollBottom --> FadeBottomShadowOut
}Props Reference
direction('vertical' | 'horizontal'): The axis to cast shadows along. Default:'vertical'.shadowSize(string): The width/height of the shadow cast. Default:'40px'.
Edge Cases
- No Overflow: If the content doesn't overflow, the shadows won't appear.
- Scroll Timeline Support: Older browsers gracefully fall back to the
background-attachmenthack.
Dependencies
- None. Pure Svelte 5 and CSS.
File Structure
src/lib/components/ScrollShadows.svelte: The component file.src/lib/components/ScrollShadows.md: This documentation file.