Gulir jendelaBy()
Contoh
Gulir dokumen 100px secara horizontal:
window.scrollBy(100, 0);
Gulir dokumen 100px secara vertikal:
window.scrollBy(0, 100);
Lebih banyak contoh di bawah ini.
Definisi dan Penggunaan
Metode scrollBy()
ini menggulir dokumen dengan jumlah piksel yang ditentukan.
Catatan
Agar scrollBy()
metode ini berfungsi, dokumen harus lebih besar dari layar, dan bilah gulir harus terlihat.
Lihat juga:
Sintaksis
window.scrollBy(x, y)
atau hanya:
scrollBy(x, y)
Parameter
Parameter | Description |
x | Required. Number of pixels to scroll (horizontally). Positive values scroll to the right, negative values to the left. |
y | Required. Number ofpixels to scroll (vertically). Positive values scroll down, negative values scroll up. |
Nilai Kembali
TIDAK ADA |
Lebih Banyak Contoh
Gulir dokumen ke atas dan ke bawah:
<button onclick="scrollWin(0, 50)">Scroll down</button>
<button onclick="scrollWin(0, -50)">Scroll up</button>
<script>
function scrollWin(x, y) {
window.scrollBy(x, y);
}
</script>
Gulir dokumen ke kanan dan kiri:
<button onclick="scrollWin(100, 0)">Scroll right</button>
<button onclick="scrollWin(-100, 0)">Scroll left</button>
<script>
function scrollWin(x, y) {
window.scrollBy(x, y);
}
</script>
Dukungan Peramban
scrollBy()
didukung di semua browser:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |