Question

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");
    }
});
Était-ce utile?

La solution

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");
        }
    });
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top