문제

/* 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.

도움이 되었습니까?

해결책

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');

다른 팁

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");
    }
}

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');
    }
}

Use .hasClass()

if($(this).hasClass("block-left")){
   $(this).addClass('fadeInLeft');
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top