2012-05-03 42 views

回答

2

所以讓我解釋一下,發生了什麼。你只是選擇了最後創建的div,所以只有那一個去了。

我必須找到所選.active和所選div

這裏是例子:

http://jsfiddle.net/JoshuaPack/YFUsJ/23/

mouseover我加入這個要頂改變activeanimation瓦爾

active = $(this).parent().find('.active'); 
    animation = $(this).parent().find('div'); 

mouseout我加了這個。

active = $(this).find('.active'); 
    animation = $(this).find('div'); 

編輯: 對於與類active移動到其他<li>對象問題,則必須將<div>附加每個.active類分別 這裏是例如:

http://jsfiddle.net/JoshuaPack/YFUsJ/31/

我做的是將動畫var包裝成.each

$.each(active, function() { 
    var animation = $('<div>').css({ 
     'position': 'absolute', 
     'height': $(this).outerHeight()-1, 
     'width': $(this).outerWidth(), 
     'marginTop': ($(this).parent().index() * $(this).outerHeight()), 
     'borderBottom': '1px solid #000', 
     'z-index': -10 
    }); 
    $(this).parent().parent().prepend(animation); 
}); 

相反或預先考慮到<ul>像以前一樣,我這樣做是爲了家長應該始終在那裏爲與類active菜單的父。

+0

非常感謝Joshua!你越來越接近了,因爲當我將主動類移到另一個主播時,它不能正常工作..你能再看一下我嗎?先謝謝了! – Jonathan

+0

http://jsfiddle.net/JoshuaPack/YFUsJ/31/ –

+0

聰明的舉動! thnx在這一個。 – Jonathan