Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在动画期间拒绝jQuery事件_Javascript_Jquery_Javascript Events - Fatal编程技术网

Javascript 在动画期间拒绝jQuery事件

Javascript 在动画期间拒绝jQuery事件,javascript,jquery,javascript-events,Javascript,Jquery,Javascript Events,在悬停时,我想设置一个div的动画。在动画期间,我想多次禁用悬停的可能性以避免动画调用。我用“unbind”删除了mouseenter事件。动画完成后,应再次添加mouseenter事件。巴德,我找不到这份工作 这里是jQuery items.hover(function (e) { $(e.currentTarget).unbind('mouseenter'); if ($(this).hasClass('xy')) { $('div.block', this)

在悬停时,我想设置一个div的动画。在动画期间,我想多次禁用悬停的可能性以避免动画调用。我用“unbind”删除了mouseenter事件。动画完成后,应再次添加mouseenter事件。巴德,我找不到这份工作

这里是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');
    }
});
非常感谢。

试试看

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

您的代码变为

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');
    }
});

添加
if($(e.is(“:animated”))返回
并从事件处理程序中删除解除绑定和绑定。@StevenWave欢迎您的帮助:)