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

133
Views
document.querySelectorAll() not working for same class within an extra div

The script works and it adds the class "complete".

window.addEventListener("scroll", function() {
    var scrollFadeClass = document.querySelectorAll(".scrollfade");

    scrollFadeClass.forEach((scrollfade) => {
        var offsetTop = window.scrollY + scrollfade.getBoundingClientRect().top;
        var scrollTop = window.scrollY;

        if (scrollTop + (window.innerHeight / 2.5) > scrollfade.offsetTop) {
                scrollfade.classList.add("complete");
            };
        });
});

The problem lies here, When scrollfade is in the 2nd section of div, it follows the if condition created

<div class="row no-gutters">
    <div class="slider scrollfade from-bottom">
        <div class="col-12 slider-container">
           <p>some text / image here</p>
        </div>
     </div>
</div>

This one doesnt follow the if condition if the scrollfade is inside the 3rd div, when i move it to the 2nd div, it suddenly follows the if condition

<div class="row no-gutters">
    <div class="slider">
        <div class="col-12 slider-container scrollfade from-bottom">
           <p>some text / image here</p>
        </div>
     </div>
</div>```
Can you please point out where the mistakes are? Thanks
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!