https://jsfiddle.net/dewit/xnq0pzx0/1/
var currentLocation = 'firstPage';
$(document).scroll(function(e){
var scrolled = $(window).scrollTop(),
secondHeight = $('#secondPage').offset().top,
thirdHeight = $('#thirdPage').offset().top;
if (scrolled > 1 && currentLocation == 'firstPage') {
currentLocation = 'secondPage';
$('body').animate({scrollTop:$('#secondPage').offset().top}, 500);
} else if (scrolled > secondHeight + 1 && currentLocation == 'secondPage') {
currentLocation = 'thirdPage';
$('body').animate({scrollTop:$('#thirdPage').offset().top}, 500);
} else if (scrolled < thirdHeight - 1 && currentLocation == 'thirdPage') {
currentLocation = 'secondPage'
$('body').animate({scrollTop:$('#secondPage').offset().top}, 500);
} else if (scrolled < secondHeight - 1 && currentLocation == 'secondPage') {
currentLocation = 'firstPage';
$('body').animate({scrollTop:$('#firstPage').offset().top}, 500);
}
})
I want to make a full page slider without plugin.
I expect this to detect current page and scroll direction and move next or previous page.
The problem is that while slide is changing, it detects new location and scroll.
As a result, it bounces up and down.
So, I want to freeze this function while slide moving.
But, I don't know how to treat this.
The problem is that the event listener is triggered when the user scrolls and also by your animation. From what I see, you want to check all the if/else statements only when user scrolls. Something like the following should help: