1
I’m trying to make a fullscreen scrolling website. That is, I do not want the scroll to stop in the middle of a section but identify if it comes from below or from above and animate to the top of the respective section. I have the following code however, it seems that the animation scroll (scrollTop) conflicts with the page scroll and I can’t 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>
<section class="red">
</section>
<section class="blue">
</section>
I understand your logic but it seems to me that you continue to create conflicts. I still can’t scroll properly after the animation. I just edited my code with your solution and only with the animation in one of the sections and when I try to leave the blue section (section with the animation) I can’t either.
– ClaraFrazao
@Clarafrazao You cannot change your question to match my answer. I have reverted to the original.
– Sam
@Clarafrazao Maybe I don’t understand exactly what you want. The page will only have these two sections or have more content below the blue section?
– Sam
@dvd I think is wanted something like this: https://projects.lukehaas.me/scrollify/#Configuration or https://alvarotrigo.com/fullPage/. That is, it should be in the next/previous section depending on the direction of the scroll (the top of the Section should be at the top of the jenela)
– Hula Hula
@dvd what I want is exactly what these plugins do. However, I just want to put the animation in one section, the last one (in the example, in blue). That is, when I get to the last section I don’t want there to be the possibility of it being in the middle. Thank you
– ClaraFrazao
@Clarafrazao I used the plugin from the first link you reported. See if this is it: https://jsfiddle.net/eunbmnak/
– Sam
this solution helped, thank you. Put in the answer here also that I already accept it
– ClaraFrazao
@Clarafrazao Updated response. Obg!
– Sam