2016-03-19 15 views
0

Her zaman div .first dosyasını gizlemeye çalışıyorum. Şu anda onları gizlemek için z-endeksi kullanıyorum ama başarısız oldum. Ne zaman istersen gizleyebilirim.Bir diğeri görünürken bir div nasıl gizlenir?

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

Güncel 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(); 
    }); 
    }); 
}); 
+0

* "Gizlemek için z-index kullanıyorum" * - Bunun için neden z-index kullanıyorsunuz? – nnnnnn

+0

Sadece görüntü sınıfını geri çevirebileceğimi düşündüm, bu yüzden javascrpt kullanmadan onları göremediniz –

cevap

0

bu neye ihtiyacınız var mı? Tıklanan ve diğerlerine gizlenen öğede resim gösterilsin mi?

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