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

118
Visualizações
Javascript removeEventListener not working on the window object

I'm trying to create the parallax effect using the intersectionObserver API. I want the event listener to be removed from the window object when the block1 section is not intersecting. but it is not letting me remove the event for some reason

const obsCallBack = function (entries) {
  entries.forEach(entry => {
    let scroll = window.scrollY;

    const functionParallex = () => {
      let enter = entry;
      if (enter.target.id === "block-1") {
        let offset = window.scrollY - scroll;
        portImg1.style.transform = 'translateY(' + (180 + offset * -0.30) + 'px)';
      }
    }
    if (entry.isIntersecting &&
      entry.boundingClientRect.y > 0) {
      window.addEventListener('scroll', functionParallex);
    }
    if (!entry.isIntersecting) {
      console.log(entry);
      window.removeEventListener('scroll', functionParallex);
    }
  })
}
const obsOptions = {
  root: null,
  threshold: 0.01,
}
const observer = new IntersectionObserver(obsCallBack, obsOptions);
observer.observe(block1);
about 4 years ago · Juan Pablo Isaza
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