Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
Scroll function only adds a class when scrolling down but doesn't remove it when scrolling to the top

I have this problem. At the bottom of a page is a fixed (position: fixed) div. When I scroll down I want to add a class to the div and when I scroll to the top the class must be removed. The following code works in the sense that it adds the class but when scrolling up it does not remove the class. So I added an alert to the else block and now if I scroll down it fires and I see a popup, which obviously makes no sense.

  $(window).scroll(function () {
    if ($(this).scrollTop() > 50) {
      $("#legalNotice").addClass("show");
    } else {
      $("#legalNotice").removeClass("show");
    }
  });

How can this be right? I tried it in multiple browsers and the same result every time.

I have another part to do the same when I scroll to the bottom and that works fine.

  $(window).scroll(function () {
    if ($(this).scrollTop() > 3000) {
      $("#legalNotice").removeClass("show");
    } else {
      $("#legalNotice").addClass("show");
    }
  });

What could the problem be?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda