Element.scrollTo()


ElementscrollTo() 方法可以使界面滚动到给定元素的指定坐标位置。

语法

element.scrollTo(x-coord, y-coord)
element.scrollTo(options)

参数

  • x-coord 是期望滚动到位置水平轴上距元素左上角的像素。
  • y-coord 是期望滚动到位置竖直轴上距元素左上角的像素。

- or -

例子

element.scrollTo(0, 1000);

Using options:

element.scrollTo({
  top: 100,
  left: 100,
  behavior: 'smooth'
});

规范

Specification Status Comment
CSS Object Model (CSSOM) View Module
element.scrollTo()
Working Draft Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
scrollToChrome Full support 45Edge No support NoFirefox Full support YesIE No support NoOpera Full support 32Safari Full support 10WebView Android Full support 45Chrome Android Full support 45Firefox Android Full support YesOpera Android Full support 32Safari iOS No support NoSamsung Internet Android Full support Yes
ScrollToOptions parameterChrome Full support 45Edge No support NoFirefox Full support YesIE No support NoOpera Full support 32Safari No support NoWebView Android Full support 45Chrome Android Full support 45Firefox Android Full support YesOpera Android Full support 32Safari iOS No support NoSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support

参考