I want to write custom scroll to sections functionality.
When I load the page and scroll down, it should scroll down the height of the window, which is fine.
Then, if scrolling down again, I want to check if the page has scrolled more than window height (which should be, if scrolling down), but it seems to be stuck at where it's at after the first scroll.
So I can get from red to yellow, but not from yellow to green.
var winHeight = window.innerHeight;
$('div').each(function(){
$(this).css('height', winHeight);
});
function scrollSections() {
var windowHeight = window.innerHeight;
var scrollTop = $(window).scrollTop();
var pos = windowHeight;
if (scrollTop > windowHeight) {
pos = windowHeight * 2;
}
$('body, html').animate({scrollTop: pos}, 1000, function() {
});
}
$( window ).on( "scroll", function() {
scrollSections();
});
Fiddle: https://jsfiddle.net/zts70yc1/