문제

I would like to remove the class .active of two elements (#information, #content) once the window has been scrolled for 50px. Here's the code how I would like to add the class .active and remove it again - sadly it doesn't work. Maybe somebody can help me?

$("#button").click(function(e) {
    e.preventDefault();
    $("#information, #content").addClass("active");
});
$(window).scroll(function(){
    if ( (!$(window).scrollTop()>50) || (!$("#information").hasClass("active")) )
    {
        $("#content").removeClass("active");
        $("#information").removeClass("active");
    }
});
도움이 되었습니까?

해결책

Try:

$("#button").click(function(e) {
        e.preventDefault();
        $("#information, #content").addClass("active");
    });
    $(window).scroll(function(){
        if($(window).scrollTop()>50) && $("#information").hasClass("active") )
        {
            $("#content").removeClass("active");
            $("#information").removeClass("active");
        }
    });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top