jquery點擊返回頁面頂部

1.html

<div id='returnTool'>返回頂部</div>

2.css (將returnTool層至於頁面底部固定不動)

<style type="text/css">
#returnTool { 
	position:absolute; 
	margin-bottom:0px;
	width:95%; 
	height:100px; 
	text-align:right;
	z-index:2; 
	overflow:hidden; 
	cursor: pointer;
} 
</style>

3.js

<script type="text/javascript">
$("#returnTool").click(function () {
	$("html,body").animate({scrollTop:"0px"},50);//50毫秒完成回到頂部動畫
})
</script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章