The Element
interface's scrollIntoView()
method scrolls the element's parent container such that the element on which scrollIntoView()
is called is visible to the user
Syntax
element.scrollIntoView(); element.scrollIntoView(alignToTop); // Boolean parameter element.scrollIntoView(scrollIntoViewOptions); // Object parameter
Parameters
alignToTop
Optional- Is a
Boolean
value:
- If
true
, the top of the element will be aligned to the top of the visible area of the scrollable ancestor. Corresponds toscrollIntoViewOptions: {block: "start", inline: "nearest"}
. This is the default value. - If
false
, the bottom of the element will be aligned to the bottom of the visible area of the scrollable ancestor. Corresponds toscrollIntoViewOptions: {block: "end", inline: "nearest"}
.
- If
scrollIntoViewOptions
Optional '- Is an Object with the following properties:
- ;;
behavior
Optional
- Defines the transition animation. One of
auto
orsmooth
. Defaults toauto
. block
Optional- Defines vertical alignment. One of
start
,center
,end
, ornearest
. Defaults tostart
. inline
Optional- Defines horizontal alignment. One of
start
,center
,end
, ornearest
. Defaults tonearest
.
Example
var element = document.getElementById("box");
element.scrollIntoView();
element.scrollIntoView(false);
element.scrollIntoView({block: "end"});
element.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"});
Notes
The element may not be scrolled completely to the top or bottom depending on the layout of other elements.
Specifications
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) View ModuleThe definition of 'Element.scrollIntoView()' in that specification. | Working Draft | Initial definition |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Chrome
Full support 29 |
Edge Full support 17 Full support 17 Notes' The only parameter supported is Notes' This function is implemented in the |
Firefox
Full support 1 |
IE Full support 5 Full support 5 Notes' This function is implemented in the |
Opera
Full support 38 |
Safari Full support 3 Full support 3 Notes' No support for |
WebView Android
Full support ≤37 |
Chrome Android
Full support 29 |
Firefox Android
Full support 4 |
Opera Android
Full support 41 |
Safari iOS Full support 1 Full support 1 Notes' No support for |
Samsung Internet Android
Full support 2.0 |
|
Chrome Full support 61 Full support 61 Notes' The |
Edge Full support 79 Full support 79 Notes' The |
Firefox Full support 36 Full support 36 Notes' No support for |
IE
No support No |
Opera Full support 48 Full support 48 Notes' The |
Safari
No support No |
WebView Android Full support 61 Full support 61 Notes' The |
Chrome Android Full support 61 Full support 61 Notes' The |
Firefox Android Full support 36 Full support 36 Notes' No support for |
Opera Android Full support 45 Full support 45 Notes' The |
Safari iOS
No support No |
Samsung Internet Android Full support 8.0 Full support 8.0 Notes' The |
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.'
- Experimental. Expect behavior to change in the future.
- See implementation notes.'
- See implementation notes.
See also
Element.scrollIntoView() by Mozilla Contributors is licensed under CC-BY-SA 2.5.