【发布时间】:2017-05-28 00:25:41
【问题描述】:
我有一些代码,其中一个 div 在元素单击时打开,其中另一个 div 位于其中。我希望它在我单击子 div 外部时关闭,但当我单击任一时它正在关闭。
HTML:
<div id="gallerybox">
<div id="webbox1" ><h1 class="codetext">Hand<br> Coded</h1></div>
<div id="webbox2"><h1 id="musich1">Wordpress<br>Sites</h1></div>
<div id="webbox3"><h1 id="musich1">Mobile Web<br> Apps</h1></div>
<div id="lightbox"><div id="webbox1result"></div></div>
</div>
CSS:
#lightbox{
height: 100vh;
width: 100vw;
z-index: 99;
position: absolute;
display: none;
opacity: 0.5;
background-color: black;
}
#webbox1result{
height: 280%;
width: 90%;
position: absolute;
opacity: 0.5;
background-color: aqua;
z-index: 100;
margin-top: 7%;
margin-left: 5%;
margin-right: 5%;
}
jquery:
$("#webbox1").click(function(){
$("#lightbox").css("display", "block");
}
);
$("#lightbox").click(function(){
$("#lightbox").css("display", "none");
}
);
【问题讨论】:
-
您可以检查目标是否是内部 div,然后在不应用 css 的情况下返回,这是您需要的吗?
标签: jquery css css-selectors parent-child lightbox