--- title: Element.scroll() slug: Web/API/Element/scroll translation_of: Web/API/Element/scroll ---
scroll() 方法是用于在给定的元素中滚动到某个特定坐标的 {{domxref("Element")}} 接口。
element.scroll(x-coord, y-coord) element.scroll(options)
x-coord 是指在元素左上方区域横轴方向上想要显示的像素。y-coord 是指在元素左上方区域纵轴方向上想要显示的像素。- or -
options 是一个 {{domxref("ScrollToOptions")}} 的字典。// 在元素上方显示1000像素 element.scroll(0, 1000);
使用 options:
element.scroll({
top: 100,
left: 100,
behavior: 'smooth'
});
| 规范 | 状态 | 注释 |
|---|---|---|
| {{ SpecName('CSSOM View', '#dom-element-scroll-options-options', 'element.scroll()') }} | {{ Spec2('CSSOM View') }} |
Initial definition. |
{{Compat("api.Element.scroll")}}