HTML DOM scrollIntoView Method
Contoh
Gulir elemen dengan id="content" ke area yang terlihat di jendela browser:
var elmnt = document.getElementById("content");
elmnt.scrollIntoView();
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Metode scrollIntoView() menggulir elemen yang ditentukan ke dalam area yang terlihat dari jendela browser.
Dukungan Peramban
Angka-angka dalam tabel menentukan versi browser pertama yang sepenuhnya mendukung metode ini.
Method | |||||
---|---|---|---|---|---|
scrollIntoView | 28.0 | 8.0 | 1.7 | 5.0 | 38.0 |
Sintaksis
element.scrollIntoView(alignTo)
Parameter
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. |
Detail Teknis
Nilai Kembali: | Tidak ada nilai kembali |
---|---|
Versi DOM | Eksperimental |
Lebih Banyak Contoh
Contoh
Gulir ke atas atau ke bawah elemen:
var elmnt = document.getElementById("content");
function scrollToTop()
{
elmnt.scrollIntoView(true); // Top
}
function scrollToBottom() {
elmnt.scrollIntoView(false); // Bottom
}