window.scrollTo

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.

Window.scrollTo() は文書内の特定の組み合わせの座標までスクロールします。

構文

window.scrollTo(x-coord, y-coord)
window.scrollTo(options)

引数

  • x-coord は、左上に表示されたい文書の水平軸上のピクセルです。
  • y-coord は、左上に表示されたい文書の垂直軸上のピクセルです。

- または -

js
window.scrollTo(0, 1000);

options の使用例:

js
window.scrollTo({
  top: 100,
  left: 100,
  behavior: "smooth",
});

Window.scroll() はこのメソッドとほぼ同じです。相対スクロールについては、 Window.scrollBy(), Window.scrollByLines(), Window.scrollByPages() を参照してください。

要素をスクロールするには、 Element.scrollTop および Element.scrollLeft を参照してください。

仕様書

Specification
CSSOM View Module
# dom-window-scrollto

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
scrollTo
options.behavior parameter
options.left parameter
options.top parameter

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.