Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!