我有两个独立的动画正在发生,其中一个在mouseenter
上触发,另一个在click
上触发。问题是,当它们都被激活时,它会创建一个跳动的动画。jQuery:单击时,阻止mouseenter事件
你可以明白我的意思是:JSFiddle
是否有可能阻止mouseenter
事件从如果click
事件被激活时发生的?
的Javascript
$('header h1').mouseenter(function() {
$('header:not(.open)').delay(500).animate({
'padding-bottom': '40px'
}, 150, function() {
//function complete
});
});
$('header h1').mouseleave(function() {
$('header:not(.open)').animate({
'padding-bottom': '20px'
}, 150, function() {
//function complete
});
});
$('header h1').click(function() {
if ($('header').hasClass('open')) {
$('header p').fadeOut(100);
$('header').removeClass('open').animate({
'padding-bottom': '20px'
}, 300, function() {
//animation complete
});
}
else {
$('header').addClass('open').animate({
'padding-bottom': '150px'
}, 300, function() {
$('header p').fadeIn();
});
}
});
为什么你需要半秒延时? – mayhewr
@mayhewr我加了延迟来强调问题。但无论如何它仍然存在。 – colindunn
看起来像取消绑定可能工作? http://api.jquery.com/unbind/ – colindunn