scrollBy method

void scrollBy([
  1. dynamic optionsOrX,
  2. dynamic y,
  3. Map? scrollOptions
])

Scrolls the page horizontally and vertically by an offset.

Other resources

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();
    }
  }
}