Element.scrollBy()

The scrollBy() method of the Element interface scrolls an element by the given amount.

Syntax

element.scrollBy(x-coord, y-coord);
element.scrollBy(options)

Parameters

  • x-coord is the horizontal pixel value that you want to scroll by.
  • y-coord is the vertical pixel value that you want to scroll by.

- or -

Examples

// scroll an element
element.scrollBy(300, 300);

Using options:

element.scrollBy({
  top: 100,
  left: 100,
  behavior: 'smooth'
});

Specification

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

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
scrollByChrome Full support 45Edge Full support 79Firefox Full support YesIE No support NoOpera Full support 32Safari Full support 10WebView Android Full support 45Chrome Android Full support 45Firefox Android Full support YesOpera Android Full support 32Safari iOS No support NoSamsung Internet Android Full support 5.0
ScrollToOptions parameterChrome Full support 45Edge Full support 79Firefox Full support YesIE No support NoOpera Full support 32Safari No support NoWebView Android Full support 45Chrome Android Full support 45Firefox Android Full support YesOpera Android Full support 32Safari iOS No support NoSamsung Internet Android Full support 5.0

Legend

Full support
Full support
No support
No support