--- title: element.scrollIntoView slug: Web/API/Element/scrollIntoView tags: - API - DOM - Element - Méthodes translation_of: Web/API/Element/scrollIntoView ---
La méthode Element.scrollIntoView() fait défiler la page de manière à rendre l'élément visible.
element.scrollIntoView(); element.scrollIntoView(alignToTop); // Paramètre booléen element.scrollIntoView(scrollIntoViewOptions); // Paramètre d'objet
alignToTop {{ optional_inline() }}est une valeur {{jsxref("Boolean")}} optionnelle qui :
true (vrai), aligne l'élément avec le haut de la zone visible de l'ancêtre défilable. Correspond à scrollIntoViewOptions: {block: "start", inline: "nearest"}. C'est la valeur par défaut.false (faux), celui-ci sera aligné en bas de la zone visible de l'ancêtre défilable. Correspond à scrollIntoViewOptions: {block: "end", inline: "nearest"}.scrollIntoViewOptions {{optional_inline}} {{experimental_inline}}behavior {{optional_inline}}"auto", "instant" ou "smooth". Par défaut : "auto".block {{optional_inline}}"start", "center", "end" ou"nearest". Par défaut : "center".inline {{optional_inline}}"start", "center", "end" ou "nearest". Par défaut : "nearest".var element = document.getElementById("box");
element.scrollIntoView();
element.scrollIntoView(false);
element.scrollIntoView({block: "end"});
element.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"});
L'élément peut ne pas être aligné complètement avec le haut ou le bas, selon la disposition des autres éléments.
| Spécification | Statut | Commentaire |
|---|---|---|
| {{SpecName("CSSOM View", "#dom-element-scrollintoview", "Element.scrollIntoView()")}} | {{Spec2("CSSOM View")}} | Définition initiale |
{{Compat("api.Element.scrollIntoView")}}