Skip to content

Instantly share code, notes, and snippets.

@petrosh
Last active December 24, 2015 05:28
Show Gist options
  • Save petrosh/6750357 to your computer and use it in GitHub Desktop.
Save petrosh/6750357 to your computer and use it in GitHub Desktop.
Simple modal box as seen on http://stackoverflow.com/a/11090278
/**
* White
*
*/
#modal-background {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: white; /* << change this for black */
opacity: .50;
-webkit-opacity: .5;
-moz-opacity: .5;
filter: alpha(opacity=50);
z-index: 1000;
}
#modal-content {
background-color: whitesmoke; /* << change this for black */
display: none;
height: 480px;
width: 640px;
margin: -240px 0 0 -320px; /* << margins = half width and height */
padding: 10px;
position: absolute;
top: 50%;
left: 50%;
z-index: 1000;
}
#modal-background.active, #modal-content.active {
display: block;
}​
<button id="modal-launcher">Launch Modal Window</button>
<div id="modal-background"></div>
<div id="modal-content">
<button id="modal-close">Close Modal Window</button>
</div>​
$(function(){
$("#modal-launcher, #modal-background, #modal-close").click(function() {
$("#modal-content, #modal-background").toggleClass("active");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment