欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery中scrollTop()方法用法實(shí)例

 更新時(shí)間:2015年01月16日 15:43:47   投稿:shichen2014  
這篇文章主要介紹了jQuery中scrollTop()方法用法,實(shí)例分析了scrollTop()方法的功能、定義及返回或設(shè)置匹配元素的滾動條的垂直偏移量時(shí)的使用技巧,需要的朋友可以參考下

本文實(shí)例講述了jQuery中scrollTop()方法用法。分享給大家供大家參考。具體分析如下:

此方法返回或設(shè)置匹配元素的滾動條的垂直偏移量。

語法結(jié)構(gòu)一:

當(dāng)scrollTop()方法不帶有參數(shù)的時(shí)候是返回匹配元素相對滾動條頂部的偏移量。

復(fù)制代碼 代碼如下:
$(selector).scrollTop()

實(shí)例代碼:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>scrollTop()函數(shù)-腳本之家</title>
<style type="text/css">
#div1{
  border:1px solid black;
  width:200px;
  height:200px;
  overflow:auto
}
#div2{height:250px;}
#div3{
  height:48px;
  width:30px;
  border:1px solid red;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    alert($("#div1").scrollTop()+" px");
  });
});
</script>
</head>
<body>
<div id="div1">
  <div id="div2">
   <div id="div3"></div>
  </div>
</div>
<button>獲得offset值</button>
</body>
</html>

語法結(jié)構(gòu)二:

當(dāng)scrollTop()方法帶有參數(shù)的時(shí)候置垂直滾動條頂部偏移為該值。

復(fù)制代碼 代碼如下:
$(selector).scrollTop(val)

參數(shù)列表:

參數(shù) 描述
val 設(shè)定垂直滾動條值

實(shí)例代碼:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>scrollTop()函數(shù)-腳本之家</title>
<style type="text/css">
#div1{
  border:1px solid black;
  width:200px;
  height:200px;
  overflow:auto
}
#div2{height:250px;}
#div3{
  height:48px;
  width:30px;
  border:1px solid red;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("#div1").scrollTop(30);
  })
})
</script>
</head>
<body>
<div id="div1">
  <div id="div2">
    <div id="div3"></div>
  </div>
</div>
<button>設(shè)置offset值</button>
</body>
</html>

希望本文所述對大家的jquery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論