Venster scrollBy()
Voorbeeld
Scroll het document 100px horizontaal:
window.scrollBy(100, 0);
Scroll het document 100px verticaal:
window.scrollBy(0, 100);
Hieronder meer voorbeelden.
Definitie en gebruik
De scrollBy()
methode verschuift het document met het opgegeven aantal pixels.
Opmerking
Om de scrollBy()
methode te laten werken, moet het document groter zijn dan het scherm en moet de schuifbalk zichtbaar zijn.
Zie ook:
Syntaxis
window.scrollBy(x, y)
of gewoon:
scrollBy(x, y)
Parameters:
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. |
Winstwaarde
GEEN |
Meer voorbeelden
Scroll het document op en neer:
<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>
Scroll naar rechts en links door het document:
<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>
Browserondersteuning
scrollBy()
wordt ondersteund in alle browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |