1、html部分
<a class = "top" href = "javascript:;"> ⬆ </a>
2、css部分
.top{
width:100px;
height:100px;
background:#666;
color:#fff;
text-align:center;
line-height:100px;
display:none;
position:fixed;
bottom:50px;
right:50px;
}
.top:hover{
background:#0ff;
}
3、js部分
for(var i=0; i<150; i++){
document.write("<h1>"+i+"</h1>");
}
$(window).scroll(function(){
var t = $(this).scrollTop();
if(t > 250){
$(".top").stop().fadeIn();
} else {
$(".top").stop().fadeOut();
}
});
$(".top").click(function(){
$("body,html").stop().animate({scrollTop:0},300);
})