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 September 2020.
scrollBy()
方法是使得元素滚动一段特定距离的 Element
接口。
Syntax
element.scrollBy(x-coord, y-coord); element.scrollBy(options)
Parameters
例子
js
// 让元素滚动
element.scrollBy(300, 300);
使用 options
:
js
element.scrollBy({
top: 100,
left: 100,
behavior: "smooth",
});
规范
Specification |
---|
CSSOM View Module # dom-element-scrollby |
浏览器兼容性
BCD tables only load in the browser