Я полагаю, что вы после этого:
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');
});
Что такое $ (это) должно быть? Потому что, формируя свой код, он выглядит как $ (this), ссылаясь на элемент ul. Если вы хотите работать над ликой этой ul, я боюсь, ваш код неправильный ... – Jibou
Можете ли вы предоставить JSFiddle? Ваш код выглядит действительным. – gdoron
Можете ли вы сказать нам, чего вы пытаетесь достичь? – Jivings