Usage
Options
| Option | Type | Default | Description |
|---|---|---|---|
| element | HTMLElement | null | The scrollable element to monitor |
| threshold | number | 50 | Pixel threshold to trigger onScrollDown |
| onScrollDown | () => void | - | Callback when scrolled past threshold |
| onScrollTop | () => void | - | Callback when scrolled back to top |
Returns
| Property | Type | Description |
|---|---|---|
| lastScrollTop | number | Last recorded scroll position |
| hasTriggeredScrollDown | boolean | Whether onScrollDown has been triggered |
Behavior
- One-time Trigger:
onScrollDownonly fires once per scroll session (until returning to top) - Top Detection:
onScrollTopfires when scroll position returns to 0 - Passive Listener: Uses passive event listener for better scroll performance
- Window Fallback: Falls back to window scroll if no element is provided