I'm trying to do a fullscreen scrolling website. That is, I do not want the scroll to stop in the middle of a section but to identify if it comes from below or from above and make an animation to the top of the respective section. I have the following code however, it looks like the scrollTop conflicts with the page scroll and I can not get out of section 1.
var lastScrollTop = 0;
$(window).on('scroll', function(event){
var st = $(this).scrollTop();
if (st > lastScrollTop){
$('html, body').stop().animate({
scrollTop: $('section').eq(1).offset().top
}, 100);
} else {
$('html, body').stop().animate({
scrollTop: $('section').eq(0).offset().top
}, 100);
}
lastScrollTop = st;
});
section {
height: 600px;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><sectionclass="red">
</section>
<section class="blue">
</section>