HTML DOM Element scrollIntoView() Method
- Previous Page scrollHeight
- Next Page scrollLeft
- Go to the Previous Level HTML DOM Elements Object
Definition and Usage
scrollIntoView()
The method scrolls an element into the visible area of the browser window.
Example
Example 1
Scroll the element with id="content" into the visible area of the browser window:
const element = document.getElementById("content"); element.scrollIntoView();
Example 2
Scroll to the top or bottom of an element:
const element = document.getElementById("content"); function scrollToTop() { element.scrollIntoView(true); } function scrollToBottom() { element.scrollIntoView(false); }
Syntax
element.scrollIntoView(align)
Parameter
Parameter | Description |
---|---|
align |
Optional. A boolean value indicating the alignment type:
If omitted, it will scroll to the top of the element. Note:Due to the layout of other elements, some elements may not scroll all the way to the top or bottom. |
Return value
None.
Browser support
All browsers support element.scrollIntoView()
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous Page scrollHeight
- Next Page scrollLeft
- Go to the Previous Level HTML DOM Elements Object