{{ APIRef("DOM")}}{{SeeCompatTable}}
The Element.scrollIntoView()
method scrolls the current element into the visible area of the browser window.
Syntax
element.scrollIntoView(); // Equivalent to element.scrollIntoView(true)
element.scrollIntoView(alignToTop); // Boolean arguments
element.scrollIntoView(scrollIntoViewOptions); // Object argument
Parameters
alignToTop
- Is a {{jsxref("Boolean")}} value:
- If
true
, the top of the element will be aligned to the top of the visible area of the scrollable ancestor. - If
false
, the bottom of the element will be aligned to the bottom of the visible area of the scrollable ancestor.
- If
scrollIntoViewOptions
- A boolean or an object with the following options:
-
{ behavior: "auto" | "instant" | "smooth", block: "start" | "end", }
- If it is a boolean,
true
corresponds to{block: "start"}
andfalse
to{block: "end"}
Example
var element = document.getElementById("box"); element.scrollIntoView(); element.scrollIntoView(false); element.scrollIntoView({block: "end"}); element.scrollIntoView({block: "end", behavior: "smooth"});
Notes
The element may not be scrolled completely to the top or bottom depending on the layout of other elements.
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName("CSSOM View", "#dom-element-scrollintoview", "Element.scrollIntoView()")}} | {{Spec2("CSSOM View")}} | Initial definition |
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatGeckoDesktop(1.0)}} | 6 | 10.0 | 4 |
scrollIntoViewOptions |
{{CompatNo}} | {{CompatGeckoDesktop(36)}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatUnknown}} | {{CompatGeckoMobile(1.0)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
scrollIntoViewOptions |
{{CompatNo}} | {{CompatGeckoMobile(36)}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
See also
- {{non-standard_inline}}
Element.scrollIntoViewIfNeeded()