I'm making a lightbox of my own.
I have a semi transparent div that is fixed over the whole screen and inside it I have the lightbox centered with my content. A div in a div.
I'm not that great with jQ so I don't know how to make sure that the click event (to close container with dimmed div and lightbox) ONLY is triggered when clicking the dimmed area and not if I click something in the lightbox.
In essence: to close down the popup and semi transparent area if clicking on the semi transparent area, BUT NOT IF I CLICK IN THE MIDDLE LIGHTBOX.
This is what I got so far: ( with lightbox centered like in https://stackoverflow.com/a/8620628/891052 )
$(document).ready( function() {
$("#openpopup").click(function() {
$('#closepopup').toggle();
});
$("#closepopup").click(function() {
$('#closepopup').toggle();
});
});
html, body {height:100%;}
#closepopup {
background:rgba(0,0,0,.5);
position:fixed;
top:0;
left:0;
THIS_CENTERS_CONTENT:;
width:100%;
height:100%;
vertical-align: middle;
text-align:center;
}
.fullheight {
THIS_CENTERS_CONTENT:;
height:100%;
vertical-align: middle;
display: inline-block;
}
#popupbox {
background:#ebebeb;
border-radius:15px;
text-align:left;
height:auto;
THIS_CENTERS_CONTENT:;
max-width:90%;
vertical-align: middle;
display: inline-block;
}
#popupboxinner {
THIS_KEEPS_CONTENT_PLACED:;
max-width:800px; SAME_AS_MAX_IMG_WIDTH:;
padding:20px 30px;
min-width:200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<div id="closepopup">
<span class="fullheight"></span>
<div id="popupbox">
<div id="popupboxinner">
LIGHTBOX CONTENT - SHOULD NOT CLOSE IF CLICKED
</div>
</div>
</div>
<span id="openpopup">OPEN CLICKABLE SEMI TRANSPARENT WRAPPER WITH LIGHTBOX INSIDE</span>