这篇翻译不完整。请帮忙从英语翻译这篇文章

摘要

滚动到文档中的某个坐标。

语法

window.scrollTo(x-coord,y-coord )

window.scrollTo(options)

参数

  • x-coord 是文档中的横轴坐标。
  • y-coord 是文档中的纵轴坐标。
  • options 是一个包含三个属性的对象:
  1. top 等同于  y-coord
  2. left 等同于  x-coord
  3. behavior  类型String,表示滚动行为,支持参数 smooth(平滑滚动),instant(瞬间滚动),默认值auto,实测效果等同于instant

例子

window.scrollTo( 0, 1000 );

// 设置滚动行为改为平滑的滚动
window.scrollTo({ 
    top: 1000, 
    behavior: "smooth" 
});

注意

该函数实际上和 window.scroll是一样的。 相对滚动可以参考 window.scrollBywindow.scrollByLines,和 window.scrollByPages

规范

DOM Level 0 不属于任何标准.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
scrollToChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung 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

文档标签和贡献者

此页面的贡献者: mdnwebdocs-bot, iugo, wp56610, lovue, zmy, hephecqq
最后编辑者: mdnwebdocs-bot,