scrollBy method
Scrolls the page horizontally and vertically by an offset.
Other resources
- Window.scrollBy from MDN.
Implementation
void scrollBy([dynamic optionsOrX, y, Map? scrollOptions]) {
final doc = document.documentElement;
if (doc == null) return;
if (optionsOrX is num) {
final dy = (y is num) ? y.toInt() : 0;
doc.scrollLeft = doc.scrollLeft + optionsOrX.toInt();
doc.scrollTop = doc.scrollTop + dy;
return;
}
if (optionsOrX is Map) {
final dx = optionsOrX['left'];
final dy = optionsOrX['top'];
if (dx is num) {
doc.scrollLeft = doc.scrollLeft + dx.toInt();
}
if (dy is num) {
doc.scrollTop = doc.scrollTop + dy.toInt();
}
}
}