Based on this awnser: How can I determine the direction of a jQuery scroll event?
I did a function like this:
tempScrollTop=0;
$.fn.cool = function(options){
windowTop = $(window).scrollTop();
if (tempScrollTop < windowTop ){
//scroll down
}
else if (tempScrollTop > windowTop ){
//scroll up
}
tempScrollTop = windowTop;
};
but each time I try to use my function
$(window).scroll(function(e) {
$("#element1").cool();
$("#element2").cool();
}
$("#element2") takes the global variable tempScrollTop already modified by $("#element1") and for element 2 tempScrollTop and windowTop has the same value, so my function doesn't work.
Any ideas on what can I do? I dont want to create n functions one for each element.