I assume you are behind this:
http://jsfiddle.net/aSr3J/20/
Essentially, your mouseleave function should look like this:
$('#lava').mouseleave(function () { left = Math.round($(".selected").offset().left - $('#lava').offset().left); width = $(".selected").width(); //Set the floating bar position, width and transition $('#box').stop(false, true).animate({left: left},{duration:1000, easing: style}); $('#box .head').stop(false, true).animate({width:width},{duration:1000, easing: style}); });
Note that I also added a color definition for the links in the stylesheet:
#lava ul a li { color:#fff; }
(Did you know that including block-level elements like li in inline elements like a is only allowed in HTML5?)
Regarding the color of the menu text, I also made changes to $('#lava li').hover(function ()) :
$('#lava li').hover(function () { //Get the position and width of the menu item left = Math.round($(this).offset().left - $('#lava').offset().left); width = $(this).width(); $(this).css("color","black"); //Set the floating bar position, width and transition $('#box').stop(false, true).animate({left: left},{duration:1000, easing: style}); $('#box .head').stop(false, true).animate({width:width},{duration:1000, easing: style}); //if user click on the menu },function() { $(this).css("color","white");}).click(function () { //reset the selected item $('#lava li').removeClass('selected'); //select the current item $(this).addClass('selected'); });
source share