THML
<body>
<div class="actGotop">
<a href="#" title="Top"></a>
</div>
</body>
CSS
body{
height: 8000px;
width: 100%;
}
a{
color: #fff;
}
.actGotop{
position: fixed;
bottom:50px;
right:50px;
width: 150px;
height: 243px;
display: none;
z-index: 100;
}
.actGotop a,.actGotop a:link{
width: 150px;
height: 243px;
display: inline-block;
background: url("images/act.jpg");
outline: none;
}
jQuery
<script src="jQuery/jquery-1.12.3.js"></script>
<script>
$(function () {
// 当页面超出1000px 让小火箭显示,小于1000px让小火箭隐藏
$(window).scroll(function () {
if($(window). scrollTop()>=1000){
$(".actGotop").fadeIn();
}else {
$(".actGotop").fadeOut();
}
});
// 在外边注册
$(".actGotop").click(function () {
$("html,body").animate({scrollTop:0});
});
});
</script>