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 2020年1月.
Element
的 scrollTo()
方法可以使界面滚动到给定元素的指定坐标位置。
语法
js
scrollTo(x-coord, y-coord)
scrollTo(options)
参数
x-coord
是你想要显示在左上角的元素沿水平轴的像素。y-coord
是你想要显示在左上角的元素沿垂直轴的像素。
- 或者 -
返回值
无 (undefined
)。
示例
js
element.scrollTo(0, 1000);
使用 options
:
js
element.scrollTo({
top: 100,
left: 100,
behavior: "smooth",
});
规范
Specification |
---|
CSSOM View Module> # dom-element-scrollto> |
浏览器兼容性
Loading…