html
<p id="to-top"><a href="#top"><span></span></a></p>
css
p#to-top{
position:fixed;
bottom:100px;
right:80px;
}
p#to-top a{
text-align:center;
text-decoration:none;
color:#d1d1d1;
display:block;
width:30px;
/*使用CSS3中的transition屬性給跳轉鏈接中的文字添加漸變效果*/
-moz-transition:color1s;
-webkit-transition:color1s;
-o-transition:color1s;
}
p#to-top a:hover{
color:#979797;
}
p#to-top a span{
background:#d1d1d1 url(./bup.png) no-repeat center center;
border-radius:6px;
display:block;
height:30px;
width:30px;
margin-bottom:5px;
/*使用CSS3中的transition屬性給<span>標簽背景顏色添加漸變效果*/
-moz-transition:background1s;
-webkit-transition:background1s;
-o-transition:background1s;
}
#to-top a:hover span{
background:#979797 url(./aup.png) no-repeat center center;
}
js
<script type="text/javascript">
$(document).ready(function(){
//隱藏#to-top
$("#to-top").hide();
//滾動條位置處于距頂部700像素以下時,跳轉鏈接出現,否則消失
$(function () {
$(window).scroll(function(){
if ($(window).scrollTop()>700){
$("#to-top").fadeIn(700);
}else{
$("#to-top").fadeOut(700);
}
});
//當點擊跳轉鏈接后,回到頁面頂部
$("#to-top").click(function(){
$('body,html').animate({scrollTop:0},500);
return false;
});
});
});
</script>
bup.png
aup.png