سؤال

I'm using mouseenter/mouseleave on a div for fading it in and out.

The problem is when quickly hovering the div it results to some kind of queue where the div keeps fading several times.

Seems like I need to stop the effect like "on mousenter then stop fading out".

Any ideas?

هل كانت مفيدة؟

المحلول

You can use .stop(), which is documented here: http://api.jquery.com/stop/

$('#hoverme-stop-2').hover(function() {
  $(this).find('img').stop(true, true).fadeOut();
}, function() {
  $(this).find('img').stop(true, true).fadeIn();
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top