Window:scroll() 方法
>Window.scroll() 方法滚动窗口至文档中的特定位置。
语法
js
scroll(xCoord, yCoord)
scroll(options)
参数
返回值
无(undefined)。
示例
html
<!-- 把纵轴上第 100 个像素置于窗口顶部 -->
<button onclick="scroll(0, 100);">点击以向下滚动到第 100 个像素</button>
使用 options:
js
window.scroll({
top: 100,
left: 100,
behavior: "smooth",
});
备注
Window.scrollTo() 实际上和该方法是相同的。有关相对滚动,请参见 Window.scrollBy()、Window.scrollByLines() 和 Window.scrollByPages()。
有关滚动元素,请参见 Element.scrollTop 和 Element.scrollLeft。
规范
| 规范 |
|---|
| CSSOM View Module> # dom-window-scroll> |