Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit a Jquery effect to one item at a time?

Tags:

jquery

I have a set of divs with a hovering effect, but if you hover over them quickly the animation just gets messy. This is the 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);
    });
});
like image 645
Abderrahim Gadmy Avatar asked Mar 12 '23 17:03

Abderrahim Gadmy


1 Answers

Try to .stop() the running animation before beginning the newer one.

$(document).ready(function(){
  $('.project').hover(function(){
    $(this).find('h3').stop().fadeIn(500); 
  }, function(){
    $(this).find('h3').stop().fadeOut(500);
  });
});
like image 98
Rajaprabhu Aravindasamy Avatar answered Mar 16 '23 03:03

Rajaprabhu Aravindasamy