How to limit jQuery effect to one element at a time?

I have a set of divs with a hover effect, but if you hover over them quickly with animation, it will become messy. This is HTML:

<a>
     <div class="project">
        <img src="img/projects/TrendyPhones.png" alt="project screenshot">
        <h3>Trendy Phones</h3>
    </div>
</a>
<a href="">
    <div class="project">
        <img src="img/projects/TrendyPhones.png" alt="project screenshot">
        <h3>Trendy Phones</h3>
    </div>
</a>
<a href="">
    <div class="project">
        <img src="img/projects/TrendyPhones.png" alt="project screenshot">
        <h3>Trendy Phones</h3>
    </div>
$(document).ready(function(){
    $('.project').hover(function(){
        $(this).find('h3').fadeIn(500); 
    }, function(){
        $(this).find('h3').fadeOut(500);
    });
});
+4
source share
1 answer

Try .stop()running the animation before starting a new one.

$(document).ready(function(){
  $('.project').hover(function(){
    $(this).find('h3').stop().fadeIn(500); 
  }, function(){
    $(this).find('h3').stop().fadeOut(500);
  });
});
+7
source

All Articles