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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
scrollByChrome Full support 45Edge No support NoFirefox Full support YesIE No support NoOpera Full support 32Safari Full support 10WebView Android Full support 45Chrome Android Full support 45Edge Mobile No support NoFirefox Android Full support YesOpera Android Full support 32Safari iOS No support NoSamsung Internet Android Full support Yes
ScrollToOptions parameterChrome Full support 45Edge No support NoFirefox Full support YesIE No support NoOpera Full support 32Safari No support NoWebView Android Full support 45Chrome Android Full support 45Edge Mobile No support NoFirefox Android Full support YesOpera Android Full support 32Safari iOS No support NoSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support

Document Tags and Contributors

Contributors to this page: mfluehr, mdnwebdocs-bot, chrisdavidmills
Last updated by: mfluehr,