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
インターフェイスのメソッドで、指定された量だけ要素をスクロールします。
構文
js
scrollBy(x-coord, y-coord)
scrollBy(options)
引数
x-coord
は、スクロールしたい水平ピクセル数です。y-coord
は、スクロールしたい垂直ピクセル数です。
- または -
返値
なし (undefined
)。
例
js
// 要素をスクロール
element.scrollBy(300, 300);
options
を使用する場合:
js
element.scrollBy({
top: 100,
left: 100,
behavior: "smooth",
});
仕様書
Specification |
---|
CSSOM View Module> # dom-element-scrollby> |
ブラウザーの互換性
Loading…