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

126
Views
Simple Intersection Observer API going in infinite rendering loop

I have this simple observer which add and removes classes based on entry.isIntersecting. Everything works fine except when view port is resized to particular size (this size is related to threshold) observer goes to infinite loop switching entry.isIntersecting. I am aware why is this happening and that this is probably a easy fix, but i just can't find it.

    const stickyNavReveal = function(entries){
      const [entry] = entries


      if(!entry.isIntersecting){
        //add class for sticky navigation
        nav.classList.add('sticky');
        toTop.classList.remove('hidden');
      } 
      else{
        nav.classList.remove('sticky');
        toTop.classList.add('hidden');
      }
    }

    const headerObserver = new IntersectionObserver(stickyNavReveal, {
      root:null,
      rootMargin:'40px',
      threshold:[0.4]
    })
    headerObserver.observe(header)
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!