Método HTML DOM scrollIntoView
Exemplo
Role o elemento com id="content" na área visível da janela do navegador:
var elmnt = document.getElementById("content");
elmnt.scrollIntoView();
Mais exemplos de "Experimente você mesmo" abaixo.
Definição e uso
O método scrollIntoView() rola o elemento especificado na área visível da janela do navegador.
Suporte ao navegador
Os números na tabela especificam a primeira versão do navegador que oferece suporte total ao método.
Method | |||||
---|---|---|---|---|---|
scrollIntoView | 28.0 | 8.0 | 1.7 | 5.0 | 38.0 |
Sintaxe
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. |
Detalhes técnicos
Valor de retorno: | Sem valor de retorno |
---|---|
Versão DOM | Experimental |
Mais exemplos
Exemplo
Role para a parte superior ou inferior de um elemento:
var elmnt = document.getElementById("content");
function scrollToTop()
{
elmnt.scrollIntoView(true); // Top
}
function scrollToBottom() {
elmnt.scrollIntoView(false); // Bottom
}