DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> js控制滾動條緩慢滾動到頂部
js控制滾動條緩慢滾動到頂部
編輯:JavaScript綜合知識     
<html>
<head>
<script type="text/javascript">
var currentPosition,timer;
function GoTop(){
	timer=setInterval("runToTop()",1);
}
function runToTop(){
	currentPosition=document.documentElement.scrollTop || document.body.scrollTop; 
	currentPosition-=10;
	if(currentPosition>0)
	{
		window.scrollTo(0,currentPosition);
	}
	else
	{
		window.scrollTo(0,0);
		clearInterval(timer);
	}
}
</script>
<style type="text/css">

</style>
</head>
<body>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">飯</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">吃</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">家</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">回</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">你</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">帶</div>
<div id="back-up" onclick="GoTop()" 
style="border:1px solid red;height:100px;width:15px;
position:fixed;cursor:pointer;right:10px;bottom:30px;">
返回頂部
</div>
<script>
window.scrollTo(0,document.body.scrollHeight);
</script>
</body>
</html>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved