To explain, if I scroll down once, the page shouldn't move based on the amount I scrolled but it should smooth scroll to the next id directly. If I scroll down once, it should scroll to the id below and if I scroll up, I want to scroll to the id above and not anywhere in between.
For reference, in the pen below, if I am on top section of this pen and I scroll down once, it shouldn't scroll a bit but instead scroll such that middle is in the view.
$(document).ready(function() {
$('div.top').click(function() {
$('html, body').animate({
scrollTop: $("div.middle").offset().top
}, 1000)
}),
$('div.middle').click(function() {
$('html, body').animate({
scrollTop: $("div.bottom").offset().top
}, 1000)
}),
$('div.bottom').click(function() {
$('html, body').animate({
scrollTop: $("div.top").offset().top
}, 1000)
})
});
body,
html {
width: 100%;
height: 100%;
margin: 0;
display: inline;
}
.top {
background-color: green;
height: 100%;
width: 100%;
display: flex;
}
.middle {
background-color: yellow;
height: 100%;
width: 100%;
display: flex;
}
.bottom {
background-color: red;
height: 100%;
width: 100%;
display: flex;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="top">
<h1>Top</h1>
</div>
<div class="middle">
<h1>Middle</h1>
</div>
<div class="bottom">
<h1>Bottom</h1>
</div>