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

86
Visualizações
Wait for a function to finish before starting next one

Probably a very simple question, but I'm a JavaScript newbie:

How do I wait for the "mouseenter" animation to be finished before starting the "mouseleave" animation?

Sometimes the mouse movement of the user is very quick but I want that animation to play completely mouseleave action is called.


$('.footer-links').on('mouseenter', function() {
  $(this).addClass('hover');
});

$('.footer-links').on('mouseleave', function() {
  $(this).removeClass('hover');
});

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

0

If you use CSS transition or animation use the respective "transitionend" or "animationend" events:

To keep the hover state whilst hovered, move the "transitionend" callback inside the "mouseleave" Event and make sure to use in CSS both the :hover and the class .hover together!

$('.footer-links').on({
  mouseenter() {
    $(this).addClass('hover');
  },
  mouseleave() {
    $(this).on("transitionend", function() {
      $(this).removeClass('hover');
    });
  }
});
.footer-links {
  transition: background 2s ease-out;
}

.footer-links:hover,
.footer-links.hover {
  background: red;
}
<div class="footer-links">TEST ONE</div>
<div class="footer-links">TEST TWO</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

about 4 years ago · Juan Pablo Isaza Relatório

0

You need to bind kind of events for checking css animation.

el.addEventListener("animationstart", function() {}, false);
el.addEventListener("animationend", function() {}, false);
el.addEventListener("animationiteration", function() {}, false);

You can add appropriate profixed-events as well like webkitAnimationEnd

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