HTML DOM Element scrollLeft Property
- Previous Page scrollIntoView()
- Next Page scrollTop
- Go to the Previous Level HTML DOM Elements Object
Definition and Usage
scrollLeft
Sets or returns the number of pixels that the element's content can be scrolled horizontally.
See also:
Example
Example 1
Get the pixel number of the scrolled content of "myDIV":
const element = document.getElementById("myDIV"); let x = elmnt.scrollLeft; let y = elmnt.scrollTop;
Example 2
Scroll the content of "myDIV" horizontally to 50 pixels and vertically to 10 pixels:
const element = document.getElementById("myDIV"); element.scrollLeft = 50; element.scrollTop = 10;
Example 3
Scroll the content of "myDIV" horizontally by 50 pixels and vertically by 10 pixels:
const element = document.getElementById("myDIV"); element.scrollLeft += 50; element.scrollTop += 10;
Example 4
Scroll the <body> content horizontally by 30 pixels and vertically by 10 pixels:
const html = document.documentElement; html.scrollLeft += 30; html.scrollTop += 10;
Syntax
Return the scrollLeft property:
element.scrollLeft
Set the scrollLeft property:
element.scrollLeft = pixels
Attribute value
Value | Description |
---|---|
pixels |
The number of pixels that the element's content can be scrolled horizontally.
|
Return value
Type | Description |
---|---|
Number | The number of pixels that the element's content can be scrolled horizontally. |
Browser support
All browsers support element.scrollLeft
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
- Previous Page scrollIntoView()
- Next Page scrollTop
- Go to the Previous Level HTML DOM Elements Object