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

175
Visualizações
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
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