jQuery Style How to - Get the scroll top offset








Question

We would like to know how to get the scroll top offset.

Answer


<!--from  www  .jav  a2 s. c  om-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
             var p = $("p:first");
             $("p:last").text( "scrollTop:" + p.scrollTop() );
        });
    </script>
  </head>
  <body>
       <p>Hello asdf asdf</p>
    </body>
</html>

The code above is rendered as follows: