HTML DOM scrollIntoView- methode
Voorbeeld
Scroll het element met id="content" naar het zichtbare gedeelte van het browservenster:
var elmnt = document.getElementById("content");
elmnt.scrollIntoView();
Meer "Probeer het zelf" voorbeelden hieronder.
Definitie en gebruik
De methode scrollIntoView() schuift het opgegeven element naar het zichtbare gedeelte van het browservenster.
Browserondersteuning
De cijfers in de tabel geven de eerste browserversie aan die de methode volledig ondersteunt.
Method | |||||
---|---|---|---|---|---|
scrollIntoView | 28.0 | 8.0 | 1.7 | 5.0 | 38.0 |
Syntaxis
element.scrollIntoView(alignTo)
Parameters:
Parameter | Type | Description |
---|---|---|
alignTo | Boolean | Optional. A boolean value that indicates the type of the align:
true - the top of the element will be aligned to the top of the visible area of the scrollable ancestor false - the bottom of the element will be aligned to the bottom of the visible area of the scrollable ancestor. If omitted, it will scroll to the top of the element. Note: Depending on the layout of other elements, some elements may not be scrolled completely to the top or to the bottom. |
Technische details
Winstwaarde: | Geen retourwaarde |
---|---|
DOM-versie | experimenteel |
Meer voorbeelden
Voorbeeld
Scroll naar de bovenkant of de onderkant van een element:
var elmnt = document.getElementById("content");
function scrollToTop()
{
elmnt.scrollIntoView(true); // Top
}
function scrollToBottom() {
elmnt.scrollIntoView(false); // Bottom
}