Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

313
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda