Pregunta

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");
    }
});
¿Fue útil?

Solución

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");
        }
    });
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top