scroll

英 [skr??l]? ?美 [skro?l]??

n.(常用于錄寫正式文件的)紙卷;書卷,畫卷,卷軸;渦卷形(裝飾);〈古〉表,目錄

vt.使成卷形;(電腦屏幕上)從上到下移動(資料等),卷頁

vi.(似卷軸般)卷起;(像展開卷軸般地)將文字顯示于屏幕

top

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

n.頂,頂部;(箱子)蓋,(書頁等的)上欄;首席;陀螺

adj.最高的;頂上的;頭等的;最大的

vt.形成頂部;達(dá)到…的頂端;處于…的最前頭;領(lǐng)導(dǎo)

vi.總結(jié);超越;高聳;結(jié)束

jquery scrollTop() 方法 語法

作用:scrollTop() 方法返回或設(shè)置匹配元素的滾動條的垂直位置。scroll top offset 指的是滾動條相對于其頂部的偏移。如果該方法未設(shè)置參數(shù),則返回以像素計(jì)的相對滾動條頂部的偏移。

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

參數(shù):

參數(shù)描述
offset? ??可選。規(guī)定相對滾動條頂部的偏移,以像素計(jì)。

注釋:該方法對于可見元素和不可見元素均有效。當(dāng)用于獲取值時,該方法只返回第一個匹配元素的 scroll top offset。當(dāng)用于設(shè)置值時,該方法設(shè)置所有匹配元素的 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 設(shè)置為 100px</button>
<br />
<button class="btn2">獲得 scroll top offset</button>
</body>
</html>
運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例