我将分解功能问题 -
如果单击“打开”(阶段1),则单击“打开更多”(阶段2),然后单击“关闭” - 打开更多(阶段2)保持打开状态。但是,如果单击“打开更多”(阶段2),然后单击“打开更多”(阶段3),然后单击“关闭” - 它们都将正常关闭。这是为什么?
“打开图片”无法正常关闭。此外,如果您打开“打开更多(第2阶段)”和“打开更多(第3阶段)”,则应在单击打开的图片时关闭它们。但它没有!
我对jquery很新,这一切都让人很困惑!
$(document).ready(function() {
$('.stage1').hide();
$("#stage1").click(function () {
$(".stage1").toggle("slide", { direction: "right" }, 1000);
});
$('.stage2').hide();
$("#stage2").click(function () {
$(".stage2").slideToggle();
e.preventDefault();
});
$('.stage3').hide();
$("#stage3").click(function () {
$(".stage3").slideToggle();
e.preventDefault();
});
$('.photos').hide();
$("#photos").click(function () {
$(".photos").slideToggle();
e.preventDefault();
});
$("#showmap").click(function () {
if ($('.stage2, .stage3').is(':hidden'))
{$(".stage1").toggle("slide", { direction: "right" }, 1000); }
else
{
$(".stage3").slideToggle();
$(".stage2").slideToggle();
$(".stage1").delay(1000).toggle("slide", { direction: "right" }, 1000);
}
});
});
----------------------------- HTML ----------------- ------------
<div id="stage1">Open</div>
<div id="showmap">close (closes all)</div>
<div class="map-wrapper">
<img src="http://placehold.it/1000x300" width="100%">
<div class="stage1 map-main-slider"> <br>
<div id="stage2">open more</div>
<div id="photos"> Open Pictures (Should close stages 2 and 3 if open) </div>
</div>
</div>
<div>
</div>
<div class="photos" style="color:#FFFFFF;font-size:14px;text-align:center;">
<div> <br> <br> <br> I am Photos <br> <br> <br> </div>
</div>
<div class="stage2" style="color:#FFFFFF;font-size:14px;text-align:center;">
<div id="stage3"> <br> <br> <br> Open More <br> <br> <br> </div>
<div class="stage3" style="color:#FFFFFF;font-size:14px;text-align:center;"><br> <br> <br>I am More Infmation <br> <br> <br> </div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
--------------------------------- CSS
.map-wrapper{
position: relative;
}
.map-main-slider {
background-color: rgba(233, 233, 233, 0.96);
background-image: url("/wordpress/wp-content/themes/penrose/img/noise.png");
bottom: 0;
height: 100%;
left: 0;
margin: 0;
position: absolute;
right: 0;
width: 100%;
}
.map-inner {
padding:4%
}
.stage2{
background:blue;
}
.stage3{
background:red;
}
.photos {background:green;}
答案 0 :(得分:0)
在Showmap中单击功能检查初始,如果检查不正确。我修改了如下代码
$("#showmap").click(function () {
if ($('.stage2').is(':hidden') && $('.stage3').is(':hidden'))
{
$(".stage1").toggle("slide", { direction: "right" }, 1000); }
else
{
$(".stage3").slideToggle();
$(".stage2").slideToggle();
$(".stage1").delay(1000).toggle("slide", { direction: "right" }, 1000);
}
});
请小提琴