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

105
Visualizações
JQuery animation chining

Greetings as stated in the title i am unable to chain multiple jQuery animation.

I need to use switchClass function to progressively toggle bootstrap classes with a specific timing to build up my animation. I would premit that i found strange this error, because i rememer that the function worked as intended few week ago. Here the code i had used :

$(button).switchClass("btn-primary", "btn-warning", 800)
$(button).switchClass("btn-warning", "btn-success", 800)
$(button).switchClass("btn-success", "btn-primary", 800);

Here a jFiddle with a minimal example of my scenario, in which i the animation does not work anymore :

https://jsfiddle.net/s6uxaLzt

So my question is, how can i execute the transition (switchClass) in the order described above?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Given your description of the goal, it appears you're attempting to have the background-color of the button element fadde between the different colours. Switching classes through JS is not an ideal way of doing that.

A better approach would be to use CSS to animate the colour changes using @keyframes. It would look something like this:

$('button').on('click', e => {
  $(e.currentTarget).addClass('animate');
}).on('animationend', e => {
  $(e.target).removeClass('animate');
});
body button.btn.btn-primary:focus {
  outline: 0;
  box-shadow: none;
}

button.animate {
  animation: background-fade 2.4s;    
}

@keyframes background-fade {
  0% { 
    background-color: #007bff; 
    border-color: #007bff; 
  }
  33% { 
    background-color: #ffc107; 
    border-color: #ffc107; 
  }
  66% { 
    background-color: #28a745; 
    border-color: #28a745; 
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
<p>Click the button to see the colour fade animation:</p>
<div class="row mt-2 ml-2">
  <button class="btn btn-primary text-uppercase edit" type="button">
    <span class="edit-label">Animate</span>
    <span class="spinner-grow spinner-grow-sm edit-spinner" role="status" aria-hidden="true" style="display:none;"></span>
  </button>
</div>

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