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 |
瀏覽器相容性
載入中…