Element.scroll()

 scroll() 方法是用于在给定的元素中滚动到某个特定坐标的 Element 接口。

Syntax

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

Parameters

  • x-coord 是指在元素左上方区域横轴方向上想要显示的像素。
  • y-coord 是指在元素左上方区域纵轴方向上想要显示的像素。

- or -

例子

// 在元素上方显示1000像素
element.scroll(0, 1000);

使用 options:

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

规范

规范 状态 注释
CSS Object Model (CSSOM) View Module
element.scroll()
Working Draft

Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
scrollChrome 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