2011-01-14 77 views
2

我试图显示和隐藏悬停元素上的元素。我的代码工作,但是当用户鼠标悬停及移出元素非常快,动画就跑甚至鼠标移开它:(jquery停止动画,如果另一个仍在运行

$('.EventNameList').hover(
    function() { 
     $(this).stop().animate({ backgroundColor: '#eaeaea' }, 200, "easeInQuad"); 
     $(this).find('div#TrainingActionButtons').show("fast"); 
    }, 
    function() { 
     $(this).stop().animate({ backgroundColor: '#ffffff' }, 800, "easeOutQuad"); 
     $(this).find('div#TrainingActionButtons').hide("fast");   
    }); 
    }); 

和HTML:

<tr> 
<td class="EventNameList"> 
    <div id="TrainingActionButtons"> 
    Some text 
    </div> 
    </td> 
</tr> 
+0

可能重复:http://stackoverflow.com/questions/4666227/jquery-issue-with-hoverintent-and-show-hide-for-div/4667207#4667207 – ifaour 2011-01-14 17:05:04

回答

0

我不知道这方面的表现,但可以告诉所有元素停止并结束,而不仅仅是当前元素。

$('.EventNameList').hover(
    function() { 
     // stop([clearqueue], [jumpToEnd]) 
     $('.EventNameList').stop(true, true); 
     $(this).animate({ backgroundColor: '#eaeaea' }, 200, "easeInQuad"); 
     $(this).find('div#TrainingActionButtons').show("fast"); 
    }, 
    function() { 
     $(this).stop().animate({ backgroundColor: '#ffffff' }, 800, "easeOutQuad"); 
     $(this).find('div#TrainingActionButtons').hide("fast");   
    }); 
}); 
+0

感谢快速反应:)我使用此代码$(this).find('div#TrainingActionButtons')。stop(true,true); 和我的作品完美 – user575900 2011-01-15 17:19:38

0

你可以尝试调用stop(true,true) - 这将清零效果队列并跳到当前正在运行的动画的结尾Read more about it here