jQuery實現的設定滾動條的位置

admin發表於2017-03-09

在很多應用中都有對滾動條位置的設定,下面就介紹一下如何使用jQuery實現此功能。

程式碼如下:

[HTML] 純文字檢視 複製程式碼
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title> 
<style type="text/css">
.container{
  height:3000px; 
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script> 
<script type="text/javascript"> 
$(function(){ 
  $("html,body").animate({"scrollTop":"300px"},1000); 
}); 
</script> 
</head> 
<body> 
<div class="container"></div> 
</body> 
</html>

以上程式碼實現了我們的要求,可以以動畫方式設定滾動條的位置。

animate()函式可以參閱jQuery animate()一章節。 

相關文章