scrollIntoView 方法
- ScrollAlignment? alignment
将此元素滚动到视图中。
一次只能指定一个对齐选项。
如果没有指定选项,则尝试滚动最小量以将元素滚动到视图中。
请注意,alignCenter 目前仅在 WebKit 平台上受支持。如果指定了 alignCenter 但不受支持,则将回退到 alignTop。
另请参阅
实现
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();
}
}