jsp代码
<div class="go-top" title="返回顶部"><img src="img/go_top.png"/></div>
js代码
$(function(){
// 回到顶部
$(window).scroll(function() {
if ($(window).scrollTop() > 0)
$(".go-top").show();
else
$(".go-top").hide();
});
$(".go-top").click(function() {
$("html, body").animate({
scrollTop : 0
}, 1000);
});
})
css代码
.go-top{
display: none;
position: fixed;
top:80%;
left: 90%;
width: 60px;
height: 60px;
cursor: pointer;
background: white;
}
.go-top img{
width: 60px;
height: 60px;
}
.go-top:hover{
background-color: gray;
opacity: 1;
filter: alpha(opacity=100);
}
效果