我有导航菜单,一旦用户点击,然后更改和淡出内容。问题是甚至子节点被隐藏了。如果我删除我的div id =“witness”和id =“believe”的所有子节点,那么它工作正常。如何排除div id =“witness”或id =“believe”的子节点?
提前致谢。
这是我的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>
答案 0 :(得分:1)
目前你有以下内容,其中find()匹配所有子'div'元素,甚至是那些嵌套在'description'元素下面的元素:
$("#description").find("div:visible").fadeOut();
要仅匹配'description'元素中可见的直接子元素,您可以使用此代码:
$("#description").children().filter(":visible").fadeOut();
有关详细信息,请参阅jQuery Traversing API documentation。
答案 1 :(得分:0)
如果淡出一个元素,那么全部其内容就会淡出,因此无法从动画中排除某些子元素。我的建议是使用一个更具体的选择器来选择你真正希望淡出的元素。