Window:scrollByLines() 方法

非標準:此特性未標準化。我們不建議在生產環境中使用非標準特性,因為它們瀏覽器支援有限,並且可能會更改或被移除。但是,在沒有標準選項的特定情況下,它們可以是合適的替代方案。

Window.scrollByLines() 方法會按指定的行數滾動文件。

語法

js
scrollByLines(lines)

引數

lines

用於滾動文件的行數。可以為正整數或負整數。

返回值

無(undefined)。

示例

html
<button id="scroll-up">Up 5 lines</button>
<button id="scroll-down">Down 5 lines</button>
js
document.getElementById("scroll-up").addEventListener("click", () => {
  window.scrollByLines(-5);
});
document.getElementById("scroll-down").addEventListener("click", () => {
  window.scrollByLines(5);
});

規範

這不屬於任何規範。

瀏覽器相容性

另見