我在jquery下拉菜單中有另一個問題。Jquery/Javascript子菜單顏色懸停
在我的示例中(鏈接在底部)我希望當我懸停3ºlevel子菜單文本顏色當前子菜單項保持懸停狀態(例如顏色黃色)。
我在代碼中的註釋,解釋問題出在哪裏。
感謝
我在jquery下拉菜單中有另一個問題。Jquery/Javascript子菜單顏色懸停
在我的示例中(鏈接在底部)我希望當我懸停3ºlevel子菜單文本顏色當前子菜單項保持懸停狀態(例如顏色黃色)。
我在代碼中的註釋,解釋問題出在哪裏。
感謝
我需要updated your fiddle here來解決這個問題。
我將懸停從ul.submenu li a
轉移到只是ul.submenu li
,以便當其子菜單2懸停在上面時,它沒有調用unhover功能。然後,我將這些樣式應用於.children('a')
標籤,如下所示:
$('ul.submenu li').hover(function() {
$(this).children('a').css({
color: '#eff803'
});
$(this).find(".submenu li:first a").stop().animate({
backgroundColor: '#0d0167'
});
}, function() {
$(this).children('a').css({
color: '#ffffff'
});
$(this).find(".submenu li:first a").stop().animate({
backgroundColor: '#0000FF'
});
});
一開始,避免css()
在那裏你可以。你最好用addClass()
和removeClass()
。定義一個包含您想要的顏色,然後懸停類(假設你的菜單裏面沒有其他<ol>
或<ul>
)使用類似
$('.menu a').hover(function() {
var $path = $(this).parents('li').find('> a').not(this);
$(this).closest('.menu').find('a').not($path).removeClass('hover');
$path.addClass('hover');
//code that animates to the colours in your hover class
$(this).addClass('hover').css('');//make it stick
});
編輯:對不起,沒想到在款式衰落
謝謝,是可能性。你現在如果有辦法,沒有addClass這樣做? $(本).find(東西)的.css( '#FFFFFF'); – Sbml 2011-01-21 14:12:27
非常感謝,這是我搜索的解決方案! – Sbml 2011-01-21 18:13:30