Método HTML DOM scrollIntoView
Ejemplo
Desplace el elemento con id="contenido" al área visible de la ventana del navegador:
var elmnt = document.getElementById("content");
elmnt.scrollIntoView();
Más ejemplos de "Pruébelo usted mismo" a continuación.
Definición y uso
El método scrollIntoView() desplaza el elemento especificado al área visible de la ventana del navegador.
Compatibilidad con navegador
Los números de la tabla especifican la primera versión del navegador que es totalmente compatible con el método.
Method | |||||
---|---|---|---|---|---|
scrollIntoView | 28.0 | 8.0 | 1.7 | 5.0 | 38.0 |
Sintaxis
element.scrollIntoView(alignTo)
Parámetros
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. |
Detalles técnicos
Valor de retorno: | Sin valor de retorno |
---|---|
Versión DOM | Experimental |
Más ejemplos
Ejemplo
Desplácese hasta la parte superior o inferior de un elemento:
var elmnt = document.getElementById("content");
function scrollToTop()
{
elmnt.scrollIntoView(true); // Top
}
function scrollToBottom() {
elmnt.scrollIntoView(false); // Bottom
}