scrollIntoView method

void scrollIntoView([
  1. ScrollAlignment? alignment
])

Scrolls this element into view.

Only one of the alignment options may be specified at a time.

If no options are specified then this will attempt to scroll the minimum amount needed to bring the element into view.

Note that alignCenter is currently only supported on WebKit platforms. If alignCenter is specified but not supported then this will fall back to alignTop.

See also:

Implementation

void scrollIntoView([ScrollAlignment? alignment]) {
  var hasScrollIntoViewIfNeeded = true;
  hasScrollIntoViewIfNeeded = JS(
    'bool',
    '!!(#.scrollIntoViewIfNeeded)',
    this,
  );
  if (alignment == ScrollAlignment.TOP) {
    this._scrollIntoView(true);
  } else if (alignment == ScrollAlignment.BOTTOM) {
    this._scrollIntoView(false);
  } else if (hasScrollIntoViewIfNeeded) {
    // TODO(srujzs): This method shouldn't be calling out to
    // `scrollIntoViewIfNeeded`. Remove this and make `scrollIntoView` match
    // the browser definition. If you intend to use `scrollIntoViewIfNeeded`,
    // use the `Element.scrollIntoViewIfNeeded` method.
    if (alignment == ScrollAlignment.CENTER) {
      this.scrollIntoViewIfNeeded(true);
    } else {
      this.scrollIntoViewIfNeeded();
    }
  } else {
    this._scrollIntoView();
  }
}