scroll

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

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

vt.使成捲形;(電腦螢?zāi)簧希纳系较乱苿樱ㄙY料等),卷頁

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()方法 範(fàn)例

<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>
執(zhí)行實(shí)例 ?

#點(diǎn)擊 "執(zhí)行實(shí)例" 按鈕查看線上實(shí)例

#