Definition and Usage..
Use the scrollBy() method to scroll a specified distance multiple times.
Tip: The scrollTo() method scrolls the document to the specified coordinates.
Return Value: No return value
Syntax : window.scrollBy(xpos, ypos) or window.scrollBy(-xpos, -ypos)
Differents way how to declare scrollBy() Method in program.
CODING:Use the scrollBy() method to scroll a specified distance multiple times.
Tip: The scrollTo() method scrolls the document to the specified coordinates.
Return Value: No return value
Syntax : window.scrollBy(xpos, ypos) or window.scrollBy(-xpos, -ypos)
Differents way how to declare scrollBy() Method in program.
<!DOCTYPE html>
<html>
<head>
<style>
body {
height:1500px;
width: 1500px;
}
button {
position: fixed;
}
</style>
</head>
<body>
<h1>Look at each scrollbar to see the effect.</h1>
<button style="margin-left:50px;" onclick="scrollWin(0, -50)">up</button><br>
<button onclick="scrollWin(-100, 0)">left</button>
<button style="margin-left:100px;" onclick="scrollWin(100, 0)">right</button><br>
<button style="margin-left:40px;" onclick="scrollWin(0, 50)">down</button><br><br>
<script>
function scrollWin(x, y) {
window.scrollBy(x, y);
}
</script>
</body>
</html>
<html>
<head>
<style>
body {
height:1500px;
width: 1500px;
}
button {
position: fixed;
}
</style>
</head>
<body>
<h1>Look at each scrollbar to see the effect.</h1>
<button style="margin-left:50px;" onclick="scrollWin(0, -50)">up</button><br>
<button onclick="scrollWin(-100, 0)">left</button>
<button style="margin-left:100px;" onclick="scrollWin(100, 0)">right</button><br>
<button style="margin-left:40px;" onclick="scrollWin(0, 50)">down</button><br><br>
<script>
function scrollWin(x, y) {
window.scrollBy(x, y);
}
</script>
</body>
</html>
Comments
Post a Comment