Window: scrollTo() 方法
Window.scrollTo() 方法可滚动到文档中的特定坐标集。
语法
js
scrollTo(xCoord, yCoord)
scrollTo(options)
参数
返回值
无(undefined)。
示例
js
window.scrollTo(0, 1000);
使用 options
js
window.scrollTo({
top: 100,
left: 100,
behavior: "smooth",
});
注意
Window.scroll() 与此方法基本相同。对于相对滚动,请参阅 Window.scrollBy()、Window.scrollByLines() 和 Window.scrollByPages()。
有关滚动元素,请参阅 Element.scrollTop 和 Element.scrollLeft。
规范
| 规范 |
|---|
| CSSOM 视图模块 # dom-window-scrollto |
浏览器兼容性
加载中…