2

我有一个 jquery 悬停事件,当您将鼠标悬停在一个元素上时会触发该事件。麻烦的是,如果您多次将鼠标悬停在元素上,它会将事件排入队列,有时会使元素闪烁好几分钟,这取决于您悬停在元素上和悬停在元素上的速度和时间。我想停止事件的传播,以便消除这种排队。

$('.pui-search-item').hover( function() {
        $(this).find('.pui-actions').show('fade');
    }, function(){
        $(this).find('.pui-actions').hide('fade');

    });

我将如何解决这个问题,我尝试了各种传播功能但没有效果。

提前致谢。

4

3 回答 3

7

试试这个:

$('.pui-search-item').hover( function() {
        $(this).find('.pui-actions').stop(true, true).show('fade');
    }, function(){
        $(this).find('.pui-actions').stop(true, true).hide('fade');

    });

这是有关 stop() http://api.jquery.com/stop/的更多信息

于 2011-05-13T13:15:03.577 回答
3

在动画之前添加一个stop(true)函数调用,以便重置队列。

于 2011-05-13T13:14:19.903 回答
1

试试这个链接。

您的实施应更改为:

$('.pui-search-item').hover(function() {
  $(this).find('.pui-actions').stop(true, true).fadeOut();
}, function() {
  $(this).find('.pui-actions').stop(true, true).fadeIn();
});
于 2011-05-13T13:17:54.507 回答