I have multiple conditional if statements wrapped in a $(window).scroll function. Each conditional if's have different $('#section').offset.top spots on the document. But, the problem is each if's statement keeps firing after a window scroll passes different sections on the page.
Below is a short example:
$(document).ready(function(){
$(window).scroll(function(){
var wScroll = $(this).scrollTop();
if(wScroll > $('#section-one').offset().top){
// do something!
console.log('foo');
}else{
//stop the something!
}
if(wScroll > $('#section-two').offset().top){
// do something!
console.log('foo');
}else{
//stop the something!
}
});
});
The console.log() still would fire both foo & bar after the user scrolls past the two offset.top points.
How can i stop the each console.log() and it's elements to fire only inside its respected sections height's and not overlap other top conditional triggers. All in order to have optimal browsing performance.
Aucun commentaire:
Enregistrer un commentaire