Element.scrollTo()
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.
Element
的 scrollTo()
方法可以使界面滚动到给定元素的指定坐标位置。
语法
js
scrollTo(x-coord, y-coord)
scrollTo(options)
参数
返回值
无 (undefined
)。
示例
js
element.scrollTo(0, 1000);
使用 options
:
js
element.scrollTo({
top: 100,
left: 100,
behavior: "smooth",
});
规范
Specification |
---|
CSSOM View Module # dom-element-scrollto |
浏览器兼容性
BCD tables only load in the browser