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

404
Visualizações
Why aren't jQuery functions being called sequentially?

I have a function that, when the Start button is pressed, a cycle is called for 10 iterations, where it generates a number from 1 to 7, which is substituted in the switch, where functions should be called in turn on the object. First change css, then call animate and then change css again, but instead they change at the same time without waiting for the end of the previous function. Why is this happening? And how to fix it?


The function

$('input[Value="Start"]').click(function () {
    $(this).css("visibility", "hidden");
    for (let i = 0; i < 10; i++) {
        note = Math.floor(Math.random() * 7) + 1;
        console.log(note);
        switch (note) {
            case 1:
                $('.SightReading_content_show_imeage_note_C').css("visibility", "visible").animate({ 'left': '20%' }, 3000).css({ "visibility": "hidden", "left":"80%"});
                break;
            case 2:
                $('.SightReading_content_show_imeage_note_D').css("visibility", "visible").animate({ 'left': '20%' }, 3000).css({ "visibility": "hidden", "left": "80%" });
                break;
            case 3:
                $('.SightReading_content_show_imeage_note_E').css("visibility", "visible").animate({ 'left': '20%' }, 3000).css({ "visibility": "hidden", "left": "80%" });
                break;
            case 4:
                $('.SightReading_content_show_imeage_note_F').css("visibility", "visible").animate({ 'left': '20%' }, 3000).css({ "visibility": "hidden", "left": "80%" });
                break;
            case 5:
                $('.SightReading_content_show_imeage_note_G').css("visibility", "visible").animate({ 'left': '20%' }, 3000).css({ "visibility": "hidden", "left": "80%" });
                break;
            case 6:
                $('.SightReading_content_show_imeage_note_A').css("visibility", "visible").animate({ 'left': '20%' }, 3000).css({ "visibility": "hidden", "left": "80%" });
                break;
            case 7:
                $('.SightReading_content_show_imeage_note_B').css("visibility", "visible").animate({ 'left': '20%' }, 3000).css({ "visibility": "hidden", "left": "80%" });
                break;
        }
    }
   $(this).css("visibility", "visible");
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Maybe you want each animation to occur 1s after the previous?

case 1:
  setTimeout(
    function(){
      $('.SightReading_content_show_imeage_note_C').css("visibility", "visible").animate({ 'left': '20%' }, 3000).css({ "visibility": "hidden", "left":"80%"})
    },
    i * 1000
  );
  break;
case 2:
  ...

about 4 years ago · Juan Pablo Isaza Relatório
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