Méthode HTML DOM scrollIntoView
Exemple
Faites défiler l'élément avec id="content" dans la zone visible de la fenêtre du navigateur :
var elmnt = document.getElementById("content");
elmnt.scrollIntoView();
Plus d'exemples "Essayez-le vous-même" ci-dessous.
Définition et utilisation
La méthode scrollIntoView() fait défiler l'élément spécifié dans la zone visible de la fenêtre du navigateur.
Prise en charge du navigateur
Les nombres dans le tableau spécifient la première version du navigateur qui prend entièrement en charge la méthode.
Method | |||||
---|---|---|---|---|---|
scrollIntoView | 28.0 | 8.0 | 1.7 | 5.0 | 38.0 |
Syntaxe
element.scrollIntoView(alignTo)
Paramètres
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. |
Détails techniques
Valeur de retour : | Aucune valeur de retour |
---|---|
Version DOM | Expérimental |
Plus d'exemples
Exemple
Faites défiler vers le haut ou vers le bas d'un élément :
var elmnt = document.getElementById("content");
function scrollToTop()
{
elmnt.scrollIntoView(true); // Top
}
function scrollToBottom() {
elmnt.scrollIntoView(false); // Bottom
}