我试图在任何时候隐藏 div .first .second 是可见的。现在我正在使用 z-index 来隐藏它们,但没有成功。如何在 .second 出现时随时隐藏 .first?
CSS
.highlight {
opacity: 100;
z-index: -1;
}
.second {
z-index: 1;
}
HTML
<div class="toggleElements"> <!---AdServer--->
<div class="first" id="adserver_contain">
<div id="ad_server"><img class="highlight" src="Images/Adserver_roll.png"></div>
</div>
<div class="second" id="ad_serverb">
<img class="img-responsive" src="Images/Adserver.png">
<div id="ad_serverb_text"><h1>Ad Server</h1><p>
Ad servers aggregate data and provide a centralized reporting interface. This aggregate determines what publishers sites get what inventory. AdsNative is the only truly independent ad server.</p></div>
</div>
</div> <!---AdServer End--->
当前的 Jquery
$(document).ready(function() {
$(".toggleElements").each(function() {
var parent = $(this);
$(this).find(".first").click(function() {
$(this).fadeToggle();
$(parent).find(".second").fadeToggle();
});
$(this).find(".second").click(function() {
$(this).fadeToggle();
$(parent).find(".first").fadeToggle();
});
});
});
最佳答案
这是您需要的吗?在单击的元素上显示图像并在所有其他元素上隐藏它?
$(document).ready(function() {
var toggleElements = $(".toggleElements"),
clickAbleDivs = toggleElements.find(' > div'),
currDiv, otherDivs, img;
$(clickAbleDivs).each(function(){
$(this).on('click', function(){
currDiv = $(this),
img = $(currDiv).find('img').show();
otherDivs = $(clickAbleDivs).not(currDiv);
otherDivs.each(function(){
$(this).find('img').hide();
});
})
});
});
关于javascript - 如何在另一个 div 可见时隐藏它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36096986/