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

221
Visualizações
How to combine intersection observer with parallax?

The problem with this parallax is that it runs on all sections of the .parallaxBg class page at the same time. Therefore, I would like to use the Intersection Observer to run parallax only when the section enters the viewport.

// Parallax -------------------------------------------------------------------------

window.addEventListener("scroll", function parallaxFunction() {
    let bg = document.querySelectorAll(".parallaxBg");

    let distance = window.pageYOffset;
    bg.forEach(parallaxBg => {
        parallaxBg.style.top = distance * -0.2 + "px";
    })
});

// Intersection observer --------------------------------------------------------------

const bgImages = document.querySelectorAll('.parallaxBg');

observer = new IntersectionObserver((entries) => {
  entries.forEach(entry => {
    console.log(entries);
    
    if (entry.intersectionRatio > 0) {
        entry.target.parallaxFunction;
    } else {
        entry.target.parallaxFunction;
      }

  });
});

bgImages.forEach(image => {
  observer.observe(image);
});
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