我認爲我的問題很簡單,但我不知道爲什麼我的jQuery不工作。 我只想讓導航從頂部滑入。通過再次點擊navIcon按鈕,應該隱藏導航並且按鈕的類名應該再次改變。jquery更改類動畫後不工作
這裏是我的代碼: jsfiddle
HTML
<div class="navIcon navIconInactive"></div>
<div id="navWrapper"></div>
CSS
.navIconInactive {
position: fixed;
z-index: 4;
width: 36px;
height: 34px;
top: 20px;
right: 25px;
cursor: pointer;
background: green;
}
.navIconActive {
position: fixed;
z-index: 4;
width: 36px;
height: 34px;
top: 20px;
right: 25px;
cursor: pointer;
background: red;
}
#navWrapper {
position: fixed;
top: -70px;
height: 70px;
width: 100%;
background: #333;
z-index: 2;
}
JQUERY
$('.navIconInactive').click(function() {
$('#navWrapper').animate({
top: '0'
}, 250, function() {
// Animation complete.
});
if ($('.navIcon').hasClass('navIconInactive')) {
$(this).removeClass('navIconInactive').addClass('navIconActive');
}
});
$('.navIconActive').click(function() {
$('#navWrapper').animate({
top: '-70'
}, 250, function() {
// Animation complete.
});
if ($('.navIcon').hasClass('navIconActive')) {
$(this).removeClass('navIconActive').addClass('navIconInactive');
}
});
'$(本)'後有生是'$( '#navWrapper')',而不是'$( 'navIcon')' – Niezborala 2014-09-24 13:25:16
感謝您的幫助。但你的jsfiddle也不起作用。當我再次單擊navIcon按鈕時,div應滑動到頂部:-70px – schlawunzius 2014-09-24 13:31:07