You are reading...

January 29th

I recently implemented this jQuery effect from ShopDev into my own blog navigation. I, because I’m such a genius :P , actually improved it so that when Javascript is turned off, it reverts back to less interesting CSS hover. So here’s the jQuery for the main navigation


jQuery("#nav li a").wrapInner("<span></span>");
jQuery("#nav li").removeClass("hover");
jQuery("#nav li a span").css("opacity","0");
jQuery("#nav li a span").hover(
	function() {
		jQuery(this).stop().animate({ opacity: 1 }, "fast")},
	function() {
		jQuery(this).stop().animate({ opacity: 0 }, "fast");
	});

The span tags are needed because you are essentially overlaying a hover state on top of a non-hover state. If Javascript is turned off, then the hover state won’t be visible.

The class “hover” needs to be removed because well… roll CSS

.hover #nav_home:hover, #nav li.active #nav_home, #nav_home span {
background-position:0 -57px;
}

Because in order to for the css hover state to work, it has to find the class “hover”, which I coded in the <li> tags. No “hover” class, no CSS hover state when Javascript is on. Notice the styling for the span tag is there too. You’ll need that.

The rest is explained in ShopDev’s tutorial. My contribution is to tweak the code a little bit to make it more usable for non-Javascript users.

Go home

Responses0View Comments

  1. New Design: The Main Navigation | Are you Insane?

    [...] I use display:inline-block on everything. It’s like nutella. I’ve already showcased the jQuery effect for the navigation, but I didn’t show the actual HTML/CSS, so here it is. There has been a flare up in the [...]

    February 3rd , 2009 at 3:22 pm

  2. Homar

    Looking good!

    February 27th , 2009 at 4:01 pm

Leave a Reply





blog comments powered by Disqus

This is my Twitter status linked to my Facebook status. Annoying, huh?

3780 lines of HTML make up the online version of the Roxiticus Golf Club handbook Charlie work indeed. 2 hours ago