My question is probably very easy. How to loop this function? Now, scroll event works only once. I'm looking for solution how to enable else function (smooth scroll goes from red div to blue div)
Here is js code:
var o = true;
if (o === true) {
$('div').scroll(function () {
if(o){
$('div').animate({
scrollTop: $("#red").offset().top
}, 1000);
o=false;
}
});
}
else {
$('div').scroll(function () {
if(o === false ){
$('div').animate({
scrollTop: $("#blue").offset().top
}, 1000);
o=true;
document.write(o);
}
});
}
HTML + CSS + JS: https://jsfiddle.net/g2jafoay/6/
What I'm looking for: when you scroll down, there is animation which take you to red div. So, I want to add animation which takes you to blue div after scroll up