scrollTop

Module

Methods

NodeList.scrollTop()
NodeList scrollTop ()
得到当前节点列表第一个节点的滚动条的垂直位置.
Return type:number
NodeList scrollTop ( value )
设置当前节点列表每个节点的滚动条的垂直位置.
Parameters:value (number) – 新的滚动条所在位置
Return type:NodeList
Returns:自身 this

Demo

得到一行的 scrollTop

<!DOCTYPE html>
<html>
<head>
  <style>
  p { margin:10px;padding:5px;border:2px solid #666; }
  </style>
  <script src="//g.alicdn.com/kissy/k/1.4.7/seed.js" data-config="{combine:true}"></script>
</head>
<body>
  <p>Hello</p><p></p>
<script>
    KISSY.use("node,sizzle",function(S,Node){
        var p = Node.all("p:first");
        Node.all("p:last").text( "scrollTop:" + p.scrollTop() );
    });
</script>    
</body>
</html>

设置 div 的 scrollTop

<!DOCTYPE html>
<html>
<head>
  <style>
div.demo {
background:#CCCCCC none repeat scroll 0 0;
border:3px solid #666666;
margin:5px;
padding:5px;
position:relative;
width:200px;
height:100px;
overflow:auto;
}
  p { margin:10px;padding:5px;border:2px solid #666;width:1000px;height:1000px; }
  </style>
  <script src="//g.alicdn.com/kissy/k/1.4.7/seed.js" data-config="{combine:true}"></script>
</head>
<body>
  <div class="demo"><h1>lalala</h1><p>Hello</p></div>
<script>
    KISSY.use("node",function(S,Node){
        Node.all("div.demo").scrollTop(300);
    });
</script>

</body>
</html>