@ sunfighter
A switch statement isn't that easy to use in this particular case because he's not just iffing over one variable.
@ doughavant
First things first: Learn to cache your jQuery variables! Google is your friend. This is a standard improvement known to have a dramatic effect on performance (in particular mobile devices, but the bigger the site, the more important it is for PCs too).
As for the question itself, I agree that this if/else stuff doesn't look too great (working on a big corporate software everyday I'm getting used to it, though – unfortunately). What you want to do is unify those functions as they all pretty much do the same. This solution is a bit tricky – does it do what you want it to do? I'm asking because it's not 100% equivalent to your code, but if it's supposed to do what I think it is, it should (hopefully) work. You can see it being put to use here:
http://jsfiddle.net/K8pTU/
Code:
function showPage( page ) {
var matchedItself = $( '#myself, #about, #animation, #banner' )
.filter(function () {
return $( this ).css( 'display' ) === 'block';
})
.first()
.hide()
.is( $( '#' + page ) );
if( matchedItself ) {
$( '#banner' ).fadeIn();
} else {
$( '#' + page ).fadeIn();
}
}
As you can see, it avoids if/else/switch constructs almost completely and rather utilizes some (still fairly simple) "jQuery magic". Reading it carefully should make it easy to understand, but if you need further explanations on how it works, just ask.