淡入淡出效果会在我悬停时重复多次

vin*_*nod 2 html jquery animation fade repeat

当我将鼠标悬停在它们上方时,我正在使用淡入淡出效果来隐藏和显示两个div.唯一的问题是,当我将鼠标悬停在它上面时动画会重复多次,即使这是偶然的,也有点烦人.

我使用.stop(true,false)方法进行动画制作.

像这样:

$('.fallInspiration').hover(
   function(){
      $(this).stop(true, false).animate({color: '#D55E8E'}, 300);
},
Run Code Online (Sandbox Code Playgroud)

但是我不知道在使用淡入淡出效果时如何解决问题.

这是我正在使用的代码:

$('.thisWeekWrap').hover(
    function()
    {
        $('.thisWeek').fadeOut(400);
        $('.thisWeekHover').fadeIn(400);
    },
    function()
    {
        $('.thisWeek').fadeIn(400);
        $('.thisWeekHover').fadeOut(400);
    }
);
Run Code Online (Sandbox Code Playgroud)

非常感谢帮助.谢谢

Mar*_*ahn 5

你回答了自己的问题:.stop()在做效果之前打电话:

$('.thisWeek').stop().fadeOut( 400 )
Run Code Online (Sandbox Code Playgroud)

如果这导致问题(可能,有时jQuery"保存"已停止的值),请尝试:

$('.thisWeek').stop().animate({ opacity : 0 }, 400);
Run Code Online (Sandbox Code Playgroud)