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;
}
var scrollableResolved = _resolveScrollable(scrollable);
var params = JSObject();
if (x != null) params.setProperty('left'.toJS, x.toInt().toJS);
if (y != null) params.setProperty('top'.toJS, y.toInt().toJS);
if (smooth) params.setProperty('behavior'.toJS, 'smooth'.toJS);
if (scrollableResolved.isA<Window>()) {
(scrollableResolved as Window).scrollTo(params);
} else if (scrollableResolved.isA<Element>()) {
(scrollableResolved as Element).scrollTo(params);
} else {
window.scrollTo(params);
}
}