1 回答
TA贡献1851条经验 获得超5个赞
希望下面的片段能帮到你
$(document).ready(function () {
$('.top').click(function() {
$('html, body').animate({
scrollTop: $(".top-section").offset().top
}, 1000)
}),
$('.middle').click(function (){
$('html, body').animate({
scrollTop: $(".middle-section").offset().top
}, 1000)
}),
$('.bottom').click(function (){
$('html, body').animate({
scrollTop: $(".bottom-section").offset().top
}, 1000)
})
$('.top-section').click(function (){
$('html, body').animate({
scrollTop: 0
}, 1000)
})
$('.middle-section').click(function (){
$('html, body').animate({
scrollTop: 0
}, 1000)
})
$('.bottom-section').click(function (){
$('html, body').animate({
scrollTop: 0
}, 1000)
})
});
body,
html {
width: 100%;
height: 100%;
margin: 0;
display: inline;
}
.top-section {
background-color: green;
height: 100%;
width: 100%;
display: flex;
}
.middle-section {
background-color: yellow;
height: 100%;
width: 100%;
display: flex;
}
.bottom-section {
background-color: red;
height: 100%;
width: 100%;
display: flex;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<div>
<h4>Click on Top,Middle.Bottom will take to the section,Click on Click on section will take to the Top</h4>
<h5 class="top">Top</h5>
<h5 class="middle">Middle</h5>
<h5 class="bottom">Bottom</h5>
</div>
<div class="top-section">
<h1>Top Section</h1>
</div>
<div class="middle-section">
<h1>Middle Section</h1>
</div>
<div class="bottom-section">
<h1>Bottom Section</h1>
</div>
添加回答
举报