This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
The Element.scrollIntoView() method scrolls the element on which it's called into the visible area of the browser window.
element.scrollIntoView(); // Equivalent to element.scrollIntoView(true) element.scrollIntoView(alignToTop); // Boolean arguments element.scrollIntoView(scrollIntoViewOptions); // Object argument
alignToTop Optional
Boolean value: true, the top of the element will be aligned to the top of the visible area of the scrollable ancestor. 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.scrollIntoViewOptions Optional
{
behavior: "auto" | "instant" | "smooth",
block: "start" | "end",
} true corresponds to {block: "start"} and false to {block: "end"}.var element = document.getElementById("box");
element.scrollIntoView();
element.scrollIntoView(false);
element.scrollIntoView({block: "end"});
element.scrollIntoView({block: "end", behavior: "smooth"});
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 |
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| Basic support | 29[1] | 1.0 (1.7 or earlier) | 8[1] | 38[1] | 5.0[1] |
scrollIntoViewOptions | No support | 36 (36) | No support | No support | No support |
| Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | 4.3[1] | 1.0 (1.0) | ? | No support | 5.0[1] |
scrollIntoViewOptions | No support | 36.0 (36) | ? | No support | No support |
[1] Supports scrollIntoView with boolean parameter, but not smooth behavior option
© 2005–2017 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