Javascript Browser Window scrollBy() Method Scroll window horizontally and vertically

Introduction

Scroll the document horizontally and vertically:

Click one of the buttons to scroll the document window.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
body {//w w w. j a v  a2s  .  co m
  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>



PreviousNext

Related