HTML DOM Element scrollIntoView() method
- Föregående sida scrollHeight
- Nästa sida scrollLeft
- Gå tillbaka till föregående nivå HTML DOM Elements-objekt
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 web browsers support element.scrollIntoView()
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Stöd | 9-11 | Stöd | Stöd | Stöd | Stöd |
- Föregående sida scrollHeight
- Nästa sida scrollLeft
- Gå tillbaka till föregående nivå HTML DOM Elements-objekt