Function: scrollToElement()
ts
function scrollToElement(target, options?): boolean;Scrolls the page so the target element enters the viewport.
Parameters
| Parameter | Type | Description |
|---|---|---|
target | Element | null | undefined | The target element. |
options | { behavior?: "auto" | "smooth"; offsetTop?: number; } | Optional scroll options. |
options.behavior? | "auto" | "smooth" | - |
options.offsetTop? | number | - |
Returns
boolean
true when the element could be scrolled into view.
Example
ts
const el = document.createElement('div')
document.body.appendChild(el)
scrollToElement(el) // => trueSince
1.0.0