I want to animate a div if class is equal to active, else I want tabItem to be top: 0; - The problem I have is the else doesn't seem to be firing, and I can't work out why.
The desired effect is that only one item is active at a time, and only the active has the negative top position.
For a working example please see: http://codepen.io/anon/pen/xIovs
jQuery:
var tabItem = $(".tab--hobbit");
function closeTab(){
tabItem.removeClass("active");
}
tabItem.click(function(event) {
event.preventDefault();
closeTab();
$(this).addClass("active");
if ($(this).hasClass('active')) {
$(this).animate({
top: -168
});
} else {
$(tabItem).animate({
top: 0
});
}
});