gpt4 book ai didi

javascript - 如何在另一个 div 可见时隐藏它?

转载 作者:行者123 更新时间:2023-11-28 06:12:15 25 4
gpt4 key购买 nike

我试图在任何时候隐藏 div .first .second 是可见的。现在我正在使用 z-index 来隐藏它们,但没有成功。如何在 .second 出现时随时隐藏 .first?

Website Reference

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com