Reputation: 43
I'm trying to apply a class to a div only when the window top is between 500 and 900 pixels but not before or after. Is this possible?
My current code only works for past 500px:
if($(this).scrollTop() >= 500) {
$('#01').addClass('selected');
} else {
$('#01').removeClass('selected');
}
Is it possible to have something this?:
if($(this).scrollTop() >= 500 <= 900) {
$('#01').addClass('selected');
} else {
$('#01').removeClass('selected');
}
Thanks!
Upvotes: 2
Views: 2279
Reputation: 9011
var windowPosY = $(this).scrollTop();
if(windowPosY >= 500 && windowPosY <= 900)
{
//do things
}
and I must admit I am curious as to how you checking said position. What event are you binding this logic to?
Upvotes: 2