mercredi 14 janvier 2015

jQuery do something WHEN an event happens

I'm trying to add 2 classes to a div, the first needs adding at the point WHEN scrolltop equals a certain amount, the second is added IF scrolltop is greater than a certain amount.


Here is my jQuery code:



var Scroll = $(window).scrollTop();
var ScrollFXfullHeight = $('.header-wrapper').height();

if (Scroll == ScrollFXfullHeight) {
$("#navigation, .hidden_menu_link_container").addClass("fixed");
} else if (Scroll > ScrollFXfullHeight) {
$("#navigation, .hidden_menu_link_container, .stop_the_jump").addClass("thinner");
}


The above solution obviously uses 2 if statements, the issue here is that the page must exactly equal ScrollFXfullHeight for the first class to be added, however, if you just quickly scroll past it then the event is not triggered.


Is there a way of saying "WHEN Scroll == ScrollFXFullHeight add class" so it does it even when it is scrolled past?


Aucun commentaire:

Enregistrer un commentaire