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>
執行實例 »

#點擊 "執行實例" 按鈕查看線上實例

#