--- title: Element.scrollIntoView() slug: Web/API/Element/scrollIntoView tags: - API - CSSOM Views - Experimentell - Methode(2) - Reference translation_of: Web/API/Element/scrollIntoView ---
Die Methode Element.scrollIntoView()
scrolled das Element in den sichtbaren Bereich des Browsers.
element.scrollIntoView(); // Gleich mit element.scrollIntoView(true)
element.scrollIntoView(alignToTop); // Boolean Argument
element.scrollIntoView(scrollIntoViewOptions); // Object Argument
alignToTop
true
wird der obere Rand des Elements an den oberen Rand des sichtbaren Bereichs im Browser gescrolled.false
wird der untere Rand des Elements an den unteren Rand des sichtbaren Bereichs im Browser gescrolled.scrollIntoViewOptions
{ behavior: "auto" | "smooth", block: "start" | "end", }
true
{block: "start"} und false {block: "end"}.
var element = document.getElementById("box"); element.scrollIntoView(); element.scrollIntoView(false); element.scrollIntoView({block: "end"}); element.scrollIntoView({block: "end", behavior: "smooth"});
Das Element wird eventuell nicht ganz nach oben oder unten gescrolled. Je nach Layout der anderen Elemente.
Specification | Status | Kommentar |
---|---|---|
{{SpecName("CSSOM View", "#dom-element-scrollintoview", "Element.scrollIntoView()")}} | {{Spec2("CSSOM View")}} | Initial definition |
{{Compat("api.Element.scrollIntoView")}}
Element.scrollIntoViewIfNeeded()