0
我已經創建了一個簡單的手風琴菜單。我的問題是當我點擊「Folder1」它展開,但當我再次單擊它時,它應該崩潰..我卡住了,無法繼續任何幫助..手風琴菜單問題
的jsfiddle - http://jsfiddle.net/nY2t7/
$(document).ready(function() {
$('#content >li').each(function(i){
hideElements($(this));
});
$('#content').click(function(event) {
$x = $(event.target);
//check if the element is the root node if so then hide all other li's and reveal the current one
if($x.parent().is('ul#content')) {
if($x.is(':visible')) { //check if its already expanded .. if so then collapse and return
$x.find('ul >li').slideUp(300 , function() {
**//return;** does not work
});
}
$('#content ul>li').each(function(i){
collapseElements($(this));
});
}
if($x.is('li'))
$x.find('ul:first > li').slideToggle(300);
});
function collapseElements(el) {
if(el.is(':visible')) {
el.slideUp(300);
}
}
function hideElements(elem) {
elem.find('ul >li').hide();
//$($e >li).hide();
}
});
謝謝亞歷山大,但爲什麼在動畫不工作後調用返回值。$ x.find('ul> li')。slideUp(300,function(){ ** // return; **不起作用 }); – user1184100 2012-04-09 07:37:40
@ user1184100,它確實有效。不過你從'function(){}'返回。不要忘記標記爲答案。 – Alexander 2012-04-09 07:56:14