現在のスクロール方向を検出するフック
このページのbodyはスクロールしないため、ここでは動作を試せません。実際のスクロール可能なページでご確認ください。
options.thresholdnumber50options.targetRefObject<HTMLElement | null>window| Prop | Type | Default |
|---|---|---|
options.threshold | number | 50 |
options.target | RefObject<HTMLElement | null> | window |
x'left'|'right'y'up'|'down'| Prop | Type | Default |
|---|---|---|
x | 'left'|'right' | - |
y | 'up'|'down' | - |
import { useScrollDirection } from '@k8ordo/ui';const { x, y } = useScrollDirection();
return (
<div>
<span>Vertical: {y}</span>
<span>Horizontal: {x}</span>
</div>
);const scrollRef = useRef<HTMLDivElement>(null);
const { y } = useScrollDirection({ target: scrollRef, threshold: 20 });
return (
<div ref={scrollRef} style={{ overflow: 'auto', height: 128 }}>
{/* scrollable content */}
</div>
);