This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use 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 spec changes.
The Element.scrollIntoView()
method scrolls the current element into the visible area of the browser window.
SyntaxEdit
element.scrollIntoView(); // Equivalent to element.scrollIntoView(true)
element.scrollIntoView(alignToTop); // Boolean arguments
element.scrollIntoView(scrollIntoViewOptions); // Object argument
Parameters
alignToTop
- 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. - 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"}
ExampleEdit
var element = document.getElementById("box");
element.scrollIntoView();
element.scrollIntoView(false);
element.scrollIntoView({block: "end"});
element.scrollIntoView({block: "end", behavior: "smooth"});
NotesEdit
The element may not be scrolled completely to the top or bottom depending on the layout of other elements.
SpecificationsEdit
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) View Module The definition of 'Element.scrollIntoView()' in that specification. |
Working Draft | Initial definition |
Browser compatibilityEdit
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1.0 | 1.0 (1.7 or earlier) | 6 | 10.0 | 4 |
scrollIntoViewOptions |
Not supported | 36 (36) | Not supported | Not supported | Not supported |
See alsoEdit
Document Tags and Contributors
Tags:
Contributors to this page:
paul.irish,
cvrebert,
Sebastianz,
flying-sheep,
fscholz,
teoli,
ziyunfei,
SphinxKnight,
kscarfone,
nairakhil13,
Sheppy,
mattbasta,
ethertank,
mathiasbynens,
vali29,
Midnightaz,
Mgjbot,
Nickolay,
RobG
Last updated by:
paul.irish,