Window.scrollBy() - Web APIs 编辑
The Window.scrollBy()
method scrolls the document in the window by the given amount.
Syntax
window.scrollBy(x-coord, y-coord); window.scrollBy(options)
Parameters
x-coord
is the horizontal pixel value that you want to scroll by.y-coord
is the vertical pixel value that you want to scroll by.
- or -
options
is aScrollToOptions
dictionary.
Examples
To scroll down one page:
window.scrollBy(0, window.innerHeight);
To scroll up:
window.scrollBy(0, -window.innerHeight);
Using options
:
window.scrollBy({ top: 100, left: 100, behavior: 'smooth' });
Notes
window.scrollBy()
scrolls by a particular amount, whereas window.scroll()
scrolls to an absolute position in the document. See also window.scrollByLines()
and window.scrollByPages()
.
Specifications
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) View Module The definition of 'window.scrollBy()' in that specification. | Working Draft | Initial definition. |
Browser Compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论