I would this code below to behave like below. 1. it will move to div1 when scrollTop is greater than 100 2. it will move to div2 when scrollTop is greater than div1.top position + 3. I can scroll back up and then it will behave the same for 1,2 when scrolling down.
currently it is stuck in div1. Can someone help figure this out?
$(window).scroll(function() {
event.preventDefault();
var div1 = $('#div1').offset();
var div2 = $('#div2').offset();
if ($(this).scrollTop() > 100) {
//move to div1
$('html, body').animate({
scrollTop: div1.top
},1000)
}
if ($(this).scrollTop() > div1.top + 100) {
$('html, body').animate({
scrollTop: div2.top
},1000)
}
});