Skip to content

useScrollTo ​

Category
Sensors

Hook for scrolling to a specific element

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

Usage ​

typescript
const trigger = useScrollTo(ref, options);
// or
const { ref, trigger } = useScrollTo(options);

Demo ​

Api ​

Parameters

NameTypeDefaultNote
targetTarget-The target element for scrolling to
options.xnumber-The horizontal position to scroll to
options.ynumber-The vertical position to scroll to
options.behavior?ScrollBehavior'auto'The scrolling behavior

Returns

boolean

Parameters

NameTypeDefaultNote
options.xnumber-The horizontal position to scroll to
options.ynumber-The vertical position to scroll to
options.behavior?ScrollBehavior'auto'The scrolling behavior

Contributors ​

Source • Demo