--- title: Element.scrollTo() slug: Web/API/Element/scrollTo tags: - API - Element - Method - Reference - scrollTo translation_of: Web/API/Element/scrollTo ---
scrollTo() 方法可以使界面滚动到给定元素的指定坐标位置。element.scrollTo(x-coord, y-coord) element.scrollTo(options)
x-coord 是期望滚动到位置水平轴上距元素左上角的像素。y-coord 是期望滚动到位置竖直轴上距元素左上角的像素。- or -
options 是一个{{domxref("ScrollToOptions")}}对象。element.scrollTo(0, 1000);
使用 options:
element.scrollTo({
top: 100,
left: 100,
behavior: 'smooth'
});
| Specification | Status | Comment |
|---|---|---|
| {{ SpecName('CSSOM View', '#dom-element-scrollto-options-options', 'element.scrollTo()') }} | {{ Spec2('CSSOM View') }} | Initial definition. |
{{Compat("api.Element.scrollTo")}}