Metoda scrollIntoView HTML DOM
Przykład
Przewiń element z id="content" do widocznego obszaru okna przeglądarki:
var elmnt = document.getElementById("content");
elmnt.scrollIntoView();
Więcej przykładów „Wypróbuj sam” poniżej.
Definicja i użycie
Metoda scrollIntoView() przewija określony element do widocznego obszaru okna przeglądarki.
Obsługa przeglądarki
Liczby w tabeli określają pierwszą wersję przeglądarki, która w pełni obsługuje tę metodę.
Method | |||||
---|---|---|---|---|---|
scrollIntoView | 28.0 | 8.0 | 1.7 | 5.0 | 38.0 |
Składnia
element.scrollIntoView(alignTo)
Parametry
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. |
Szczegóły techniczne
Wartość zwrotu: | Brak wartości zwrotu |
---|---|
Wersja DOM | Eksperymentalny |
Więcej przykładów
Przykład
Przewiń w górę lub w dół elementu:
var elmnt = document.getElementById("content");
function scrollToTop()
{
elmnt.scrollIntoView(true); // Top
}
function scrollToBottom() {
elmnt.scrollIntoView(false); // Bottom
}