For instance, if I have three divs, each with the class of "sectionBox" and the ids of "one", "two" and "three", respectively, how would I detect and return the id of one that leaves the page after scrolling? I would guess I should use a "this" keyword, but I'm unclear how to use one without an event handler using jQuery.
Essentially what I'm trying to do is take this code and consolidate it so I don't have to use it three or four more times.
jQuery
$(document).scroll(function(){
var threeQuartersBox = $(".sectionBox").height()*.75;
if($(window).scrollTop() < threeQuartersBox){
$("body, #colorBar, #navBarWrapper").addClass("myBlue", 200).removeClass("myRed", 200);
console.log("Something happened.");
}else if($(window).scrollTop() > threeQuartersBox){
$("body, #colorBar, #navBarWrapper").addClass("myRed", 200).removeClass("myBlue", 200);
console.log("Something NEW happened.")
}
//console.log($(window).scrollTop());
//console.log($(".sectionBox").height());
});//endScrollFunction
})()
Aucun commentaire:
Enregistrer un commentaire