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

172
Views
Execute functions in order inside "if" statements

I have some functions

function growSeparator() {
    $('.applications-worth-module__separator').addClass('applications-worth-module__separator--active');
}
function reachPkt1() {
    $('.point-1-separator').addClass('point-separator--pkt1_active');
}
function reachPkt2() {
    $('.point-2-separator').addClass('point-separator--pkt2_active');
}
function reachPkt3() {
    $('.point-3-separator').addClass('point-separator--pkt3_active');
}
function reachPkt4() {
    $('.point-4-separator').addClass('point-separator--pkt4_active');
}

Every one of them adds css class with keyframes animation inside. I try to execute a function when element reaches middle screen. I'm using getBoundingClientRect to do it.

var pkt1 = document.querySelector(".point-1__container");
var pkt2 = document.querySelector(".point-2__container");
var pkt3 = document.querySelector(".point-3__container");
var pkt4 = document.querySelector(".point-4__container");

window.addEventListener('scroll', (e) => {
   if (pkt1.getBoundingClientRect().top < window.innerHeight/2) {
        growSeparator();
   }
   if (pkt1.getBoundingClientRect().top < (window.innerHeight/2)) {
        reachPkt1(); 
   }
   if (pkt2.getBoundingClientRect().top < (window.innerHeight/2)) {
        reachPkt2();
   }
   if (pkt3.getBoundingClientRect().top < (window.innerHeight/2)) {
        reachPkt3();
   }
   if (pkt4.getBoundingClientRect().top < (window.innerHeight/2)) {
        reachPkt4();
   }
})

The problem is - when I scroll to the last element, every function fires at the same time, not one by one. I tried to use "animationend" and "transitionend" event, but it works only for one element and for other four - not.

How can I achieve this effect, when I scroll to the last element (.point-4__container) all of my previous functions execute one after another?

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!