Our volunteers haven't translated this article into 한국어 yet. Join us and help get the job done!
You can also read the article in English (US).

Summary

Scrolls the window to a particular place in the document.

Syntax

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

Parameters

  • x-coord is the pixel along the horizontal axis of the document that you want displayed in the upper left.
  • y-coord is the pixel along the vertical axis of the document that you want displayed in the upper left.

- or -

  • options is an object with three possible properties:
    • top, which is the same as the y-coord
    • left, which is the same as the x-coord
    • behavior, which is a string containing one of smooth, instant, or auto; default is auto

Example

<!-- put the 100th vertical pixel at the top of the window -->

<button onClick="scroll(0, 100);">click to scroll down 100 pixels</button>

Change the scrolling behavior

If you are looking to change how the scrolling works, you can specify that in the options object:

window.scroll({
  top: 1000,
  behavior: "smooth"
});

Notes

Window.scrollTo() is effectively the same as this method. For scrolling a particular distance, use Window.scrollBy().

Also see Window.scrollByLines(), Window.scrollByPages() and Element.scrollIntoView().

Specification

Specification Status Comment
CSS Object Model (CSSOM) View Module
The definition of 'window.scroll()' in that specification.
Working Draft

Initial definition.

Browser Compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support Yes ? Yes ? ? ?
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes ? Yes ? ? ?

문서 태그 및 공헌자

최종 변경: lucian95,