手风琴菜单问题

问题描述:

我已经创建了一个简单的手风琴菜单。我的问题是当我点击“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(); 
    } 
}); 

,工程最简单的代码:

$('#content').click(function(event) { 
    var $el = $(event.target); 
    $el.find('ul:first > li').slideToggle(300);  
}); 

虽然,它是无状态的这是一件坏事。

+0

谢谢亚历山大,但为什么在动画不工作后调用返回值。$ x.find('ul> li')。slideUp(300,function(){ ** // return; **不起作用 }); – user1184100 2012-04-09 07:37:40

+0

@ user1184100,它确实有效。不过你从'function(){}'返回。不要忘记标记为答案。 – Alexander 2012-04-09 07:56:14