Javascript 在动画期间拒绝jQuery事件
在悬停时,我想设置一个div的动画。在动画期间,我想多次禁用悬停的可能性以避免动画调用。我用“unbind”删除了mouseenter事件。动画完成后,应再次添加mouseenter事件。巴德,我找不到这份工作 这里是jQueryJavascript 在动画期间拒绝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)
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欢迎您的帮助:)