Window:scrollByLines() 方法

非标准: 该特性是非标准的,请尽量不要在生产环境中使用它!

Window.scrollByLines() 方法按指定的行数滚动文档。

语法

js
scrollByLines(lines)

参数

lines

滚动文档的行数,可以是正整数或负整数。

返回值

无(undefined)。

示例

html
<!-- 将文档向上滚动 5 行 -->
<button id="scroll-up" onclick="scrollByLines(-5);">向上 5 行</button>

<!-- 将文档向下滚动 5 行 -->
<button id="scroll-down" onclick="scrollByLines(5);">向下 5 行</button>

规范

这不属于任何规范。

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
scrollByLines
Non-standard

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Non-standard. Check cross-browser support before using.

参见