Window scrollBy() Method - Scroll the document horizontally and vertically: - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window scrollBy

Description

Window scrollBy() Method - Scroll the document horizontally and vertically:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
body {//www .  j  a va2s .  com
    height: 7500px;
    width: 5000px;
}

button {
    position: fixed;
}
</style>
</head>
<body>

<button onclick="scrollWin(0, 50)">Scroll down</button><br><br>

<button onclick="scrollWin(0, -50)">Scroll up</button><br><br>

<button onclick="scrollWin(100, 0)">Scroll right</button><br><br>

<button onclick="scrollWin(-100, 0)">Scroll left</button><br><br>

<script>
function scrollWin(x, y) {
    window.scrollBy(x, y);
}
</script>

</body>
</html>

Related Tutorials