我有兩個獨立的動畫正在發生,其中一個在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