this method is used to set the position of vertical scroll bar for a particular element.
0 Position of scrollbar means it is at the Top.
In a web page, when ever we want to adjust the scrollbar according to its content, we make use of this method.
It takes the position of scrollbar to the top for clear visibility of content for a particular web page
Syntax:
$(selector).scrollTop()
Example:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert($("div").scrollTop() + " px");
});
});
</script>
</head>
<body>
<div style="border:1px solid black;width:150px;height:100px;overflow:auto">
Evon tech located at it park in Dehradun
Twinkle, twinkle, little star, How I wonder what you are!</div><br>
<button>Return the vertical position of the scrollbar</button>
<p>Move the scrollbar down and click the button again.</p>
</body>
</html>
0 Comment(s)