2015-03-03 45 views
0

我正在爲學校建設手風琴,我覺得它應該可以工作。我知道我有一切,直到if else語句。任何建議讚賞手風琴故障我在製作

$(document).ready(function() { 

    // 
    // Set up a click event handler for clicked <li> 
    // 
    $('#accordion li').click(function() { 

     // find first ul that is a child of this (the clicked <li>) 
     var $nextUL = $(this).children('ul:first-child'); 

     // Select all siblings of the clicked <li> and then 
     // select any direct children <ul>'s 
     // that are visible - this is so we can close any visible 
     // <ul> before opening the <ul> for the clicked <li> 
     var $visibleSiblings = $(this).siblings().children('ul:visible'); 

     // If any other <ul>s are visible, slide the visible <ul> 
     // up and then, after the slide up is complete, slide down 
     // the clicked <li>'s <ul> into view 
     if ($visibleSiblings.length > 0) { 
      $visibleSiblings.slideUp('normal', function() { 
      $nextUL.fadeIn('normal'); 
      }); 

     } else { 
      // either no <ul>s were open (open the clicked item) 
      // or the user clicked on the currently open one so close it 
      $nextUL.slideToggle('normal'); 
     } 
    }); 
}); 
+0

您有任何HTML可以使用它,因此我們可以測試嗎? – mkaatman 2015-03-03 01:50:20

+0

在邏輯上似乎沒有任何不規則。但對於手風琴,我們預計'fadeIn()'是'slideDown()'。什麼是/不是在做什麼?在jsfiddle.net中的演示將有所幫助。 – charlietfl 2015-03-03 01:51:15

+0

我從來沒有用過jsfiddle,但這裏是一個鏡頭。 http://jsfiddle.net/m6fo2z4y/1/ – cmey5084 2015-03-03 01:55:02

回答