* {
margin: 0;
padding: 0;
}
.contain {
width: 70px;
height: 350px;
overflow: hidden;
position: fixed;
top: 20px;
left: 200px;
float: left;
position: fixed;
left: 30px;
top: 10px;
}
.block {
width: 70px;
overflow: hidden;
}
.block li {
list-style: none;
width: 70px;
height: 50px;
line-height: 50px;
text-align: center;
background-color: black;
color: #fff;
margin-bottom: 5px;
cursor: pointer;
}
.block li:hover {
background-color: blue;
}
.content {
float: left;
margin-left: 200px;
width: 400px;
height: 3000px;
}
.content div {
width: 400px;
height: 300px;
line-height: 300px;
text-align: center;
background-color: black;
margin-bottom: 20px;
color: #fff;
font-size: 22px;
}
.top {
width: 42px;
height: 42px;
background-color: blue;
position: fixed;
right: 0;
bottom: 0;
color: #fff;
text-align: center;
}
<div class="contain">
<ul class="block">
<li data-in="go1">1</li>
<li data-in="go2">2</li>
<li data-in="go3">3</li>
<li data-in="go4">4</li>
<li data-in="go5">5</li>
<li data-in="go6">6</li>
</ul>
</div>
<div class="content">
<div id="go1">11</div>
<div id="go2">22</div>
<div id="go3">33</div>
<div id="go4">44</div>
<div id="go5">55</div>
<div id="go6">66</div>
</div>
<div class="top">返回顶部</div>
$(".block li").click(function(e) {
var target = e.target;
var id = $(target).data("in")
$('html,body').animate({
scrollTop: $("#" + id).offset().top
}, 800)
})
$(".top").click(function() {
$('html,body').animate({
scrollTop: 0
}, 800)
})