Skip to content
0

katanakit-js / useScrollToElement

Function: useScrollToElement() ​

ts
function useScrollToElement(target, options?): boolean;

Defined in: src/infrastructure/viewport/viewport.service.ts:201

Scrolls an element into view.

Parameters ​

ParameterTypeDescription
targetstring | HTMLElementAn HTMLElement or a CSS selector string.
optionsScrollOptionsScroll options (behavior, block, inline).

Returns ​

boolean

true if the element was found and scrolled to.

Example ​

ts
useScrollToElement("#section-2", { behavior: "smooth", block: "start" });

Released under the MIT License.