我试图随时隐藏div .first。第二个是可见的。现在我正在使用z-index来隐藏它们但是没有成功。我怎么能随时隐藏.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();
});
});
});
答案 0 :(得分:0)
这是你需要的吗?在单击的项目上显示图像并将其隐藏在所有其他项目中?
$(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();
});
})
});
});