Element.scroll()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.
scroll()
方法是用于在给定的元素中滚动到某个特定坐标的 Element
接口。
语法
js
scroll(x-coord, y-coord)
scroll(options)
参数
返回值
无 (undefined
)。
示例
js
// 将元素沿垂直方向向下滚动 1000 个像素
element.scroll(0, 1000);
使用 options
:
js
element.scroll({
top: 100,
left: 100,
behavior: "smooth",
});
规范
Specification |
---|
CSSOM View Module # dom-element-scroll |
浏览器兼容性
BCD tables only load in the browser