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