简体   繁体   English

当另一个可见时如何隐藏div?

[英]How to hide a div when another is visible?

I am trying to hide div .first anytime .second is visible. 我试图在任何时候隐藏div .first .second可见。 Right now I'm using z-index to hide them but have been unsuccessful.How can I hide .first anytime .second appears? 现在我正在使用z-index隐藏它们,但是没有成功。如何在任何时候隐藏.first .second出现?

Website Reference 网站参考

CSS 的CSS

.highlight  {
opacity: 100;
z-index: -1;
}   

.second {
z-index: 1;    
}  

HTML 的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--->

Current Jquery 当前的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();
    });
  });
});

Is this what you need? 这是您需要的吗? Show image on item that is clicked and hide it in all others? 在单击的项目上显示图像,然后在所有其他项目中隐藏图像?

$(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();
        });
      })      
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM