Skip to content

useScroll ​

Category
Sensors

Hook that allows you to control scroll a element

typescript
import { useScroll } from '@siberiacancode/reactuse';

Usage ​

typescript
const scrolling = useScroll(ref, options);
// or
const scrolling = useScroll(ref, () => console.log('callback'));
// or
const [ref, scrolling] = useScroll(options);
// or
const [ref, scrolling] = useScroll(() => console.log('callback'));

Demo ​

Api ​

Parameters

NameTypeDefaultNote
options.behavior?ScrollBehaviorautoThe behavior of scrolling
options.offset.left?number0The left offset for arrived states
options.offset.right?number0The right offset for arrived states
options.offset.top?number0The top offset for arrived states
options.offset.bottom?number0The bottom offset for arrived states
options.onScroll?(params: UseScrollCallbackParams, event: Event) => void-The callback function to be invoked on scroll
options.onStop?(event: Event) => void-The callback function to be invoked on scroll end

Returns

boolean

Parameters

NameTypeDefaultNote
callback?(params: UseScrollCallbackParams, event: Event) => void-The callback function to be invoked on scroll

Returns

boolean

Parameters

NameTypeDefaultNote
targetTarget-The target element to scroll
options.behavior?ScrollBehaviorautoThe behavior of scrolling
options.offset.left?number0The left offset for arrived states
options.offset.right?number0The right offset for arrived states
options.offset.top?number0The top offset for arrived states
options.offset.bottom?number0The bottom offset for arrived states
options.onScroll?(params: UseScrollCallbackParams, event: Event) => void-The callback function to be invoked on scroll
options.onStop?(event: Event) => void-The callback function to be invoked on scroll end

Parameters

NameTypeDefaultNote
targetTarget-The target element to scroll
callback?(params: UseScrollCallbackParams, event: Event) => void-The callback function to be invoked on scroll

Contributors ​

Source • Demo