Showing posts with label Jquery scrollTop(). Show all posts
Showing posts with label Jquery scrollTop(). Show all posts

Jquery scrollTop() method


The scrollTop() method sets or returns the vertical scrollbar position for the selected elements. When the scrollbar is on the top, the position is 0.

Syntax



$(selector).scrollTop()




Example 


<!DOCTYPE html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/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:100px;height:150px;overflow:auto">
    this is nitin kumar . this is nitin kumar. this is nitin kumar  this is nitin kumar . this is nitin kumar .
  </div><br>
  <p>Move the scrollbar down and click the button again and again.</p>
  <button> alert  value of vertical position of the scrollbar</button>
</body>
</html>