API上写的看不懂啊 获取匹配元素相对滚动条顶部的偏移。  是什么意思 是滚动条离顶部的距离还是文本离顶部的距离

解决方案 »

  1.   

    这种问题你测试下就知道了,alert弹出来看看即可
    scrollTop()可以得到高度,也就是滚动条滚动高度
    scrollleft是左侧,应该是你获取的元素里滚动条的距离
      

  2.   

    scrollTop()滚动条向下移动的距离,同理left
      

  3.   

    官方文档的解释有点含糊,其实换个角度就很容易理解了,scrollTop获取的是内部元素超出外部容器的高度。
    例如:$('window').scrollTop()获取的就是当前这个页面超出窗口最上端的高度,scrollLeft与此同理
      

  4.   

    scrollTop, scrollLeft 
    返回已经滚动到元素的左边界或上边界的像素数。只有在元素有滚动条的时候,例如,元素的 CSS overflow 属性设置为 auto 的时候,这些像素才有用。这些属性也只在文档的 <body> 或 <html> 标记上定义(这和浏览器有关),并且一起来制定滚动文档的位置。注意,这些属性并不会指定一个 <iframe> 标记的滚动量。这是非标准的但却得到很好支持的属性。
    具体的看一下下面这个图
    http://www.cnblogs.com/freewind/archive/2008/05/20/1203183.html
      

  5.   

    <script  type="text/javascript">
            
            var aa = $("#as").scrollTop();
            alert(a);
        </script>
    我测试一下 是null <div style="height: 115px"></div>
        <div id="as">
        
        asdas
        
        </div>
      

  6.   


    我测试一下 是null <div style="height: 115px"></div>
      <div id="as">
        
      asdas
        
      </div>
    <script type="text/javascript">
        
      var aa = $("#as").scrollTop();
      alert(a);
      </script>
      

  7.   

    <html>
    <head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $(".btn1").click(function(){
        $("div").scrollTop(100);
      });
      $(".btn2").click(function(){
        alert($("div").scrollTop()+" px");
      });
    });
    </script>
    </head>
    <body>
    <div style="border:1px solid black;width:200px;height:200px;overflow:auto">
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
    </div>
    <button class="btn1">把 scroll top offset 设置为 100px</button>
    <br />
    <button class="btn2">获得 scroll top offset</button>
    </body>
    </html>