Skip to content

Instantly share code, notes, and snippets.

@bob1171
Last active November 24, 2017 16:30
Show Gist options
  • Save bob1171/cd12ec0f090ca368b19573c6bcd4795b to your computer and use it in GitHub Desktop.
Save bob1171/cd12ec0f090ca368b19573c6bcd4795b to your computer and use it in GitHub Desktop.

To use this put in your html document:
<script type="text/javascript" src="https://is.gd/popupjs"></script>
and
<link rel="stylesheet" href="https://is.gd/popupcss">
Then, call popup() with the args as html code that you want to be in the popup.

.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
/* The Close Button */
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
function popup(content){
var modal = document.createElement('popup');
//create x
var span = document.createElement("close")[0];
span.innerHTML = '&times;';
modal.appendChild(span)
// When the user clicks the button, open the modal
modal.style.display = "block"
// When the user clicks on <span> (x), close the modal
span.onclick = function(){modal.style.display = "none"}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
document.body.appendChild(modal)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment