1

在悬停时,我想为 div 设置动画。在动画期间,我想多次禁用悬停可能性以避免动画调用。我用“unbind”删除了 mouseenter 事件。动画完成后,应该再次添加 mouseenter 事件。Bud我无法完成这项工作。

这里是 jQuery

items.hover(function (e) {
    $(e.currentTarget).unbind('mouseenter');
    if ($(this).hasClass('xy')) {
        $('div.block', this).addClass('xxx').removeClass('zzz').animate({
            top: '0'
        });
    }
}, function (e) {
    if ($(this).hasClass('xy')) {
        $('div.block', this).animate({
            top: topHeightVal
        }, 200, function () {
            $(e.currentTarget).bind('mouseenter');
        }).addClass('zzz').removeClass('xxx');
    }
});

非常感谢。

4

1 回答 1

2

尝试.stop()

停止匹配元素上当前正在运行的动画。

你的代码变成

items.hover(function (e) {
    $(e.currentTarget).unbind('mouseenter');
    if ($(this).hasClass('xy')) {
        $('div.block', this).addClass('xxx').removeClass('zzz').stop(true, true).animate({
            top: '0'
        });
    }
}, function (e) {
    if ($(this).hasClass('xy')) {
        $('div.block', this).stop(true, true).animate({
            top: topHeightVal
        }, 200).addClass('zzz').removeClass('xxx');
    }
});
于 2013-11-06T14:12:10.073 回答