Metodo HTML DOM scrollIntoView
Esempio
Scorri l'elemento con id="content" nell'area visibile della finestra del browser:
var elmnt = document.getElementById("content");
elmnt.scrollIntoView();
Altri esempi "Provalo da solo" di seguito.
Definizione e utilizzo
Il metodo scrollIntoView() fa scorrere l'elemento specificato nell'area visibile della finestra del browser.
Supporto browser
I numeri nella tabella specificano la prima versione del browser che supporta completamente il metodo.
Method | |||||
---|---|---|---|---|---|
scrollIntoView | 28.0 | 8.0 | 1.7 | 5.0 | 38.0 |
Sintassi
element.scrollIntoView(alignTo)
Parametri
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. |
Dettagli tecnici
Valore di ritorno: | Nessun valore di ritorno |
---|---|
Versione DOM | Sperimentale |
Altri esempi
Esempio
Scorri verso l'alto o verso il basso di un elemento:
var elmnt = document.getElementById("content");
function scrollToTop()
{
elmnt.scrollIntoView(true); // Top
}
function scrollToBottom() {
elmnt.scrollIntoView(false); // Bottom
}