scrollTo method

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

Scrolls the page horizontally and vertically to a specific point.

This method is identical to scroll.

Other resources

Implementation

void scrollTo([dynamic optionsOrX, y, Map? scrollOptions]) {
  final doc = document.documentElement;
  if (doc == null) return;

  if (optionsOrX is num) {
    doc.scrollLeft = optionsOrX.toInt();
    doc.scrollTop = (y is num) ? y.toInt() : doc.scrollTop;
    return;
  }

  if (optionsOrX is Map) {
    final left = optionsOrX['left'];
    final top = optionsOrX['top'];
    if (left is num) {
      doc.scrollLeft = left.toInt();
    }
    if (top is num) {
      doc.scrollTop = top.toInt();
    }
  }
}