Reputation: 68650
/* If the object is completely visible in the window... */
if( bottom_of_window > bottom_of_object ){
$(this).is(".block-left").addClass('fadeInLeft');
$(this).is(".block-right").addClass('fadeInRight');
}
I wand to addClass by checking the elements class, but this doesn't seem to work.
Upvotes: 0
Views: 141
Reputation: 57105
Use .hasClass()
if($(this).hasClass("block-left")){
$(this).addClass('fadeInLeft');
}
Upvotes: 0
Reputation: 780724
You have to use if
if( bottom_of_window > bottom_of_object ){
if ($(this).is(".block-left")) {
$(this).addClass('fadeInLeft');
} else if ($(this).is(".block-right"))
$(this).addClass('fadeInRight');
}
}
Upvotes: 0
Reputation: 38102
You can use hasClass():
if( bottom_of_window > bottom_of_object ){
if($(this).hasClass("block-left")) {
$(this).addClass("fadeInLeft");
} else if($(this).hasClass("block-right")) {
$(this).addClass("fadeInRight");
}
}
Upvotes: 0
Reputation: 388316
You need to use filter() instead of is() because is()
returns a boolean value which will cause an error
$(this).filter(".block-left").addClass('fadeInLeft');
$(this).filter(".block-right").addClass('fadeInRight');
Upvotes: 1