您的代碼是穩定的,但是,您正在添加BEFORE類的動畫檢查。
我簡單地移動了你的動畫檢查,並防止點擊甚至改變類。
// jQuery 1.11.0 on DOM ready
var $hamburgerMenuButton = $('#burgerButton');
var $navTitle = $('.navigation-item');
var $score = $('.score');
$hamburgerMenuButton.click(function(e) {
e.stopPropagation();
if (!$hamburgerMenuButton.hasClass('open')) {
console.log('hamburgerMenuButton does NOT have class open');
if ($navTitle.is(':animated')) {
$score.append('<br>animating ');
return false;
}
$hamburgerMenuButton.addClass('open');
console.log('class open ADDED to hamburgerMenuButton');
$score.append('<br>class open ADDED ');
var delay = 0;
$navTitle.each(function(){
$(this).delay(delay).animate({
'margin-left':'0px'
},500,'easeOutQuint');
delay += 33;
}); // animation end
$score.append('<br>clicked ');
} // if end
else {
console.log('hamburgerMenuButton does HAVE class open');
if ($navTitle.is(':animated')) {
$score.append('<br>animating ');
return false;
}
$hamburgerMenuButton.removeClass('open');
console.log('class open REMOVED from hamburgerMenuButton');
$score.append('<br>class open REMOVED ');
var delay = 0;
$navTitle.each(function(){
$(this).delay(delay).animate({
'margin-left':'10em'
},500,'easeOutQuint');
delay += 33;
}); // animation end
$score.append('<br>clicked again');
} // else end
}); // $hamburgerMenuButton click end
https://jsfiddle.net/gregborbonus/b2tw65hf/3/
[改正小提琴](https://jsfiddle.net/b2tw65hf/4/)與[答案](http://stackoverflow.com/a/36392062/1010918)。 – lowtechsun