scrollTo function
Scrolls viewport to x
,y
.
- If
smooth
istrue
will animate the scroll. - If
delayMs
>= 1 it will scroll after a Future.delayed. (value in milliseconds) scrollable
is the element to scroll. Ifnull
it will be the window or thebody
, identifying which one is scrolled.
Implementation
void scrollTo(num? x, num? y,
{bool smooth = true, int? delayMs, Object? scrollable}) {
if (delayMs != null && delayMs > 0) {
_callAsync(
delayMs, () => scrollTo(x, y, smooth: smooth, scrollable: scrollable));
return;
}
scrollable = _resolveScrollable(scrollable);
final params = {
if (x != null) 'left': x.toInt(),
if (y != null) 'top': y.toInt(),
if (smooth) 'behavior': 'smooth',
};
if (scrollable is Window) {
scrollable.scrollTo(params);
} else if (scrollable is Element) {
scrollable.scrollTo(params);
} else {
window.scrollTo(params);
}
}