English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
scrollIntoView()The method will scroll the element that calls it into the visible area of the browser window.
Note:Due to the layout of other elements, the element may not be able to scroll to the top or bottom completely.
element.scrollIntoView(alignToTop)
var elem = document.getElementById("box"); elem.scrollIntoView();Test and See‹/›
The numbers in the table specify the first browser version that fully supports the scrollIntoView() method:
Method | |||||
scrollIntoView() | 28 | 3.5 | 38 | 5.1 | 8 |
Parameters | Description |
---|---|
alignToTop | (Optional) A boolean value indicating the alignment type: true-The top of the element will align with the top of the visible area of the scrollable ancestor false-The bottom of the element will align with the bottom of the visible area of the scrollable ancestor. If omitted, it will scroll to the top of the element. Note:Some elements may not be able to scroll to the top or bottom completely due to the layout of other elements. |
Return Value: | None |
---|---|
DOM Version: | CSS Object Model (CSSOM) |
Scroll to the top or bottom of an element:
var elem = document.getElementById("box"); function scrollToTop() { elem.scrollIntoView(true); } function scrollToBottom() { elem.scrollIntoView(false); }Test and See‹/›