2009-11-18 143 views
0

我有導航菜單,一旦用戶點擊,然後更改和淡入內容。問題是甚至孩子節點變得隱藏起來。如果我刪除了我的div id =「witness」和id =「believe」的所有子節點,那麼它工作正常。如何排除div id =「witness」或id =「believe」的子節點?jquery淡入淡出內容

在此先感謝。

這裏是我的javascript

$(function(){ 
    $("#content-linkwrap .hrefmenu").click(function(){ 

     $clicked = $(this); 
     // if the button is not already "transformed" AND is not animated 

      // each button div MUST have a "xx-button" and the target div must have an id "xx" 
      var idToLoad = $clicked.attr("id").split('-'); 

      //we search trough the content for the visible div and we fade it out 
      $("#description").find("div:visible").fadeOut("fast", function(){ 
       //once the fade out is completed, we start to fade in the right div 
       $(this).parent().find("#"+idToLoad[0]).fadeIn(); 
      }) 

    }); 
}); 

這裏是我的html

<div align="center" id="content-linkwrap"><a href="#" class="link-black hrefmenu" id="witness-href">WITNESS</a><a href="#" class="link-black hrefmenu" id="believe-href">BELIEVE</a></div> 

     <div id="description"> 
      <div id="witness" class="desc">    
       <div class="top"><div class="bottom"><div class="left"><div class="right"><div class="bl"><div class="br"><div class="tl"><div class="tr"> 
        <div style="padding: 40px 20px;"> 
         <h3 class="text-orange">WITNESS</h3> 
         <p class="aboutus wpad10" align="justify">To a company that has initiated major retail projects representing more than US $10 million in investments. 
         </p> 
         <p class="aboutus" align="justify">To a conglomerate so solid and expansive with far-reaching business interests and investments in food service, real estate, electronics, heavy equipment, jewelry trading, travel, and hardware trading that spans the Philippines, Hong Kong, Singapore and Malaysia. </p>     
        </div>      
        <div class="clearleft"></div> 
       </div></div></div></div></div></div></div></div> 
      </div> 

      <div id="believe" class="desc">     
       <div class="top"><div class="bottom"><div class="left"><div class="right"><div class="bl"><div class="br"><div class="tl"><div class="tr"> 
        <div style="padding: 40px 20px;"> 
         <h3 class="text-orange">BELIEVE</h3> 
         <p class="aboutus wpad10" align="justify">In a corporation that toasts not only the successes – but also the opportunities. 
         </p> 
         <p class="aboutus wpad10" align="justify">In a business entity that puts a high premium on freedom and creative participation of its people at all levels…</p> 
         <p class="aboutus wpad10" align="justify">In a management that is committed to corporate expansion, to the personal growth of its people, and to partnerships and ventures that are mutually beneficial…</p>    
        </div>      
        <div class="clearleft"></div> 
       </div></div></div></div></div></div></div></div> 
      </div>              
     </div>  

回答

1

目前你有以下內容,其中查找()所有的孩子「DIV」元素甚至是嵌套在「說明」元素深下匹配:

$("#description").find("div:visible").fadeOut(); 

爲了只是比賽的直接子「說明」元素,其是可見的,您可以使用此代碼來代替:

$("#description").children().filter(":visible").fadeOut(); 

欲瞭解更多信息,請參閱jQuery Traversing API documentation

+0

嗨馬特, 非常感謝。它的工作完美。 我非常自豪地使用這個論壇。 – tirso 2009-11-18 11:04:58

0

如果你淡出的元素,然後所有其內容被淡出,所以沒有辦法排除某些子元素形成動畫。我的建議是使用更具體的選擇器來選擇你真正想淡出的元素。