2009-11-18 145 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

如果你淡出的元素,然后所有其内容被淡出,所以没有办法排除某些子元素形成动画。我的建议是使用更具体的选择器来选择你真正想淡出的元素。