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

305
Vistas
Hide an element when scroll to specific class

I Used this JQuery code to have a sticky "Go to top" button:

//sticky back-to-top button
(function (t) {
  t(window).bind("scroll", function () {
    500 < t(this).scrollTop()
      ? t(".back-to-top").fadeIn(400)
      : t(".back-to-top").fadeOut(400);
  }),
    t(".back-to-top").click(function () {
      t("html, body").animate({ scrollTop: "0px" }, 500);
    });
})(jQuery);

this code works correctly. but i want when this sticky button reaches a specific class called "go-top", disappears. sorry for my bad english.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use interception observer so when the target element with said class is in view, it triggers the callback to hide the button.

Example: The code might not be exact but it is meant to point in the direction to follow.

let options = {
    root: document.querySelector('.go-top'),
    rootMargin: '0px',
    threshold: 1.0
 }
let prevRatio = 0.0;
let observer = new IntersectionObserver(callback, options);

let target = document.querySelector('#back-to-top-button');
observer.observe(target);

function handleIntersect(entries, observer) {
  entries.forEach((entry) => {
    if (entry.intersectionRatio > prevRatio) {
      entry.target.style.display = "none";
    } else {
      entry.target.style.backgroundColor = "block";
    }

    prevRatio = entry.intersectionRatio;
  });
}

Let me know how it goes...

You can switch the root to null but this makes the button disappear as soon as the element with the class is in the viewport

about 4 years ago · Juan Pablo Isaza Denunciar
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