This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The Element.scrollIntoView()
method scrolls the element on which it's called into the visible area of the browser window.
element.scrollIntoView(); element.scrollIntoView(alignToTop); // Boolean parameter element.scrollIntoView(scrollIntoViewOptions); // Object parameter
alignToTop
Optional
Boolean
value: true
, the top of the element will be aligned to the top of the visible area of the scrollable ancestor. Corresponds to scrollIntoViewOptions: {block: "start", inline: "nearest"}
. This is the default value.false
, the bottom of the element will be aligned to the bottom of the visible area of the scrollable ancestor. Corresponds to scrollIntoViewOptions: {block: "end", inline: "nearest"}
.scrollIntoViewOptions
Optional
behavior
Optional
"auto"
, "instant"
, or "smooth"
. Defaults to "auto"
.block
Optional
"start"
, "center"
, "end"
, or "nearest"
. Defaults to "center"
.inline
Optional
"start"
, "center"
, "end"
, or "nearest"
. Defaults to "nearest"
.var element = document.getElementById("box"); element.scrollIntoView(); element.scrollIntoView(false); element.scrollIntoView({block: "end"}); element.scrollIntoView({behavior: "instant", block: "end", inline: "nearest"});
The element may not be scrolled completely to the top or bottom depending on the layout of other elements.
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) View Module The definition of 'Element.scrollIntoView()' in that specification. | Working Draft | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 29 | 12
|
1 | 8
|
38 | 5
|
scrollIntoViewOptions
|
61
|
? | 36
|
No | 48
|
No |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | ? | 4 | Yes | 5
|
? |
scrollIntoViewOptions
|
61
|
61
|
? | 36
|
48
|
No | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/element/scrollIntoView