Element.scrollBy()
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月.
scrollBy() 方法是使得元素滚动一段特定距离的 Element 接口。
Syntax
element.scrollBy(x-coord, y-coord); element.scrollBy(options)
Parameters
x-coord是元素要在横轴上滚动的距离。y-coord是元素要在纵轴上滚动的距离。
- or -
options是一个ScrollToOptions字典。
例子
js
// 让元素滚动 element.scrollBy(300, 300); 使用 options:
js
element.scrollBy({ top: 100, left: 100, behavior: "smooth", }); 规范
| Specification |
|---|
| CSSOM View Module> # dom-element-scrollby> |