jQuery动画悬停闪烁失控

Voo*_*ger 2 jquery hover jquery-animate

我在缩略图上使用以下代码作为悬停函数:

$(function (){      
  $('.button').hover(function() {  
    if ($(this).is(":not(animated)")) {
      $(this).animate({opacity: 0.7}, 'fast');
    }
  },
  function() {
    $(this).animate({opacity: 1}, 'fast' );
  });
});
Run Code Online (Sandbox Code Playgroud)

问题是,当我过快地翻过拇指时,效果会持续闪烁一段时间...有什么东西我可以添加到if块来防止这种情况吗?

Tat*_*nen 5

用于stop()在开始新动画之前停止当前动画,它应该工作:

$(function (){      
    $('.button').hover(function() {  
        $(this).stop().animate({opacity: 0.7}, 'fast');
    },
    function(){
        $(this).stop().animate({opacity: 1}, 'fast' );
    });
});
Run Code Online (Sandbox Code Playgroud)