scroll()
方法是用于在给定的元素中滚动到某个特定坐标的 Element
接口。
Syntax
element.scroll(x-coord, y-coord) element.scroll(options)
Parameters
x-coord
是指在元素左上方区域横轴方向上想要显示的像素。y-coord
是指在元素左上方区域纵轴方向上想要显示的像素。
- or -
options
是一个ScrollToOptions
的字典。
例子
// 在元素上方显示1000像素
element.scroll(0, 1000);
使用 options
:
element.scroll({
top: 100,
left: 100,
behavior: 'smooth'
});
规范
规范 | 状态 | 注释 |
---|---|---|
CSS Object Model (CSSOM) View Module element.scroll() |
Working Draft |
Initial definition. |
浏览器兼容性
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.