话不多说 上代码
<style>
*{margin: 0;padding: 0;}
.list{
margin-bottom: 20px;
height: 3000px;
background: slateblue
}
.btn{
float: right;
background: seagreen;
padding: 20px;
}
.con{
height:3000px;
background: skyblue;
}
</style>
<ul class="list">
<div class="con"></div>
</ul>
<button class="btn">回到顶部</button>
<script src="https://code.jquery.com/jquery-3.1.1.min.js</script>
$(function(){
$(window).scroll(function(){
if($(this).scrollTop()>1500){
$(".con").fadeIn();
}else{
$(".con").fadeOut();
}
});
$(".btn").click(function(){
if ($(window).scrollTop() > 0) {
$("html,body").animate({ scrollTop: 0 }, 600);
}
})
})