本文使用jquery實現返回頂部功能,在頁面右下角顯示藍色方塊,含向上箭頭,點擊方塊即可一返回到頁面頂部。
效果預覽網址:
http:///keleyi/phtml/totop/2.htm
完整源代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>藍色方塊返回頂部--</title>
<script type="text/javascript" src="http:///keleyi/pmedia/jquery-1.10.1.min.js"></script>
<style type="text/css">
body{margin:0px;}
a{color:White;}
</style>
</head>
<body>
<div style="background-color:#959822; width:100%;height:150px;">請滾動鼠標使頁面向下</div>
<div style="background-color:Green; width:100%;height:150px;">www.
<br /><a href="http:///dev/94fb5964c80ee829.htm" target="_blank">綠色箭頭圖片返回頂部效果</a>
<br /><a href="http:///a/bjac/7cc2358ac924ebc5.htm" target="_blank">藍色方塊返回頂部</a>
<br /><a href="http:///a/bjac/6f008786225269ac.htm" target="_blank">純文本返回頂部</a>
<br /><a href="http:///a/bjac/8aa32432160f9aa4.htm" target="_blank">漂亮的返回頂部、底部和留言</a>
</div>
<div style="background-color:Red; width:100%;height:150px;">歡迎</div>
<div style="background-color:Yellow; width:100%;height:150px;">hi</div>
<div style="background-color:Silver; width:100%;height:150px;"></div>
<div style="background-color:Aqua; width:100%;height:150px;"></div>
<div style="background-color:Fuchsia; width:100%;height:150px;">keleyi</div>
<div style="background-color:Green; width:100%;height:150px;"></div>
<div style="background-color:Blue; width:100%;height:150px;"></div>
<div style="background-color:Olive; width:100%;height:150px;"> 返回頂部</div>
<div style="background-color:Green; width:100%;height:150px;">A</div>
<div style="background-color:Purple; width:100%;height:150px;">jquery</div>
<div style="background-color:Green; width:100%;height:150px;"><a href="http:///a/bjac/6f008786225269ac.htm" target="_blank">原文</a></div>
<div style="background-color:Lime; width:100%;height:150px;"></div>
<div style="background-color:Orange; width:100%;height:150px;">完整代碼</div>
<div style="height:130px;"></div>
<script type="text/javascript" src="http:///keleyi/phtml/totop/2/scrolltopcontrol.js"></script>
</body>
</html>