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

84
Views
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 answers
Answer question

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 Report

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 Report
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!