あなたが求めているのはこれだと思います:
http://jsfiddle.net/aSr3J/20/
基本的に、mouseleave 関数は次のようにする必要があります。
$('#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});
});
スタイル シートにリンクの色の定義も追加したことに注意してください。
#lava ul a li { color:#fff; }
li
(インライン要素のようにブロックレベルの要素を囲むことa
は、HTML5 でのみ有効であることをご存知ですか?)
メニューテキストの色については、以下も修正しました $('#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');
});