<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="js/jquery-2.1.0.js" ></script>
<title></title>
<style>
.gao{
width: 100%;
height: 1100px;
}
.top{
width: 80px;
height: 60px;
line-height: 60px;
position:fixed;
right: 10px;
bottom: 30px;
background: green;
color: white;
text-align: center;
display: none;
cursor: pointer;
}
</style>
</head>
<body>
<div class="gao"></div>
<div class="top">回到顶部</div>
</body>
<script>
$(document).scroll(function(){
var scrtops = $(document).scrollTop();
if(scrtops>110){
$('.top').fadeIn();
}else{
$('.top').fadeOut();
}
console.log(scrtops)
})
$('.top').click(function(){
var s =$('body').scrollTop();
$('body').animate({scrollTop:0},100)
})
</script>
</html>
转载于:https://www.cnblogs.com/yangjiansong/p/6538711.html