scroll

英 [skrəʊl]   美 [skroʊl]  

n.(常用于录写正式文件的)纸卷;书卷,画卷,卷轴;涡卷形(装饰);〈古〉表,目录

vt.使成卷形;(电脑屏幕上)从上到下移动(资料等),卷页

vi.(似卷轴般)卷起;(像展开卷轴般地)将文字显示于屏幕

top

英 [tɒp]   美 [tɑ:p]  

n.顶,顶部;(箱子)盖,(书页等的)上栏;首席;陀螺

adj.最高的;顶上的;头等的;最大的

vt.形成顶部;达到…的顶端;处于…的最前头;领导

vi.总结;超越;高耸;结束

jquery scrollTop() 方法 语法

作用:scrollTop() 方法返回或设置匹配元素的滚动条的垂直位置。scroll top offset 指的是滚动条相对于其顶部的偏移。如果该方法未设置参数,则返回以像素计的相对滚动条顶部的偏移。

语法:$(selector).scrollTop(offset)

参数:

参数描述
offset    可选。规定相对滚动条顶部的偏移,以像素计。

注释:该方法对于可见元素和不可见元素均有效。当用于获取值时,该方法只返回第一个匹配元素的 scroll top offset。当用于设置值时,该方法设置所有匹配元素的 scroll top offset。

jquery scrollTop() 方法 示例

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.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>
运行实例 »

点击 "运行实例" 按钮查看在线实例