我认为我的问题很简单,但我不知道为什么我的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