Definition and Usage..
The scrollTo() method scrolls the document to the specified coordinates.
Tip: Use the scrollBy() method to scroll a specified distance multiple times.
Return Value: No return value
Syntax : window.scrollTo(xpos, ypos) or window.scrollTo(-xpos, -ypos)
Differents way how to declare scrollTo() Method in program.
CODING:The scrollTo() method scrolls the document to the specified coordinates.
Tip: Use the scrollBy() method to scroll a specified distance multiple times.
Return Value: No return value
Syntax : window.scrollTo(xpos, ypos) or window.scrollTo(-xpos, -ypos)
Differents way how to declare scrollTo() Method in program.
<!DOCTYPE html>
<html>
<head>
<style>
body {
width: 10000px;
height: 10000px;
}
</style>
</head>
<body>
<button onclick="scrollver()">5000 vertically scroll</button>
<button onclick="scrollhor()">5000 horizontally scroll</button>
<button onclick="scrollboth()">5000 vertically & 5000 horizontallyscroll</button>
<script>
function scrollver() {
window.scrollTo(0,5000);//also use -(value)
}
function scrollhor() {
window.scrollTo(5000,0);
}
function scrollboth() {
window.scrollTo(5000,5000);
}
</script>
</body>
</html>
<html>
<head>
<style>
body {
width: 10000px;
height: 10000px;
}
</style>
</head>
<body>
<button onclick="scrollver()">5000 vertically scroll</button>
<button onclick="scrollhor()">5000 horizontally scroll</button>
<button onclick="scrollboth()">5000 vertically & 5000 horizontallyscroll</button>
<script>
function scrollver() {
window.scrollTo(0,5000);//also use -(value)
}
function scrollhor() {
window.scrollTo(5000,0);
}
function scrollboth() {
window.scrollTo(5000,5000);
}
</script>
</body>
</html>
Comments
Post a Comment