Skip to content

Instantly share code, notes, and snippets.

@mikeislearning
Created August 14, 2013 15:02
Show Gist options
  • Save mikeislearning/6231906 to your computer and use it in GitHub Desktop.
Save mikeislearning/6231906 to your computer and use it in GitHub Desktop.
My attempt at a modal box. The positioning is kind of weird though, I'm sure how to perfectly center it - requires jquery - uses sass/compass
<div id="overlay"></div>
<div id="modal">
<div id="content">
<div class="modal_header">
<h3> some title</h3>
<a href="#" id="modal-close"></a>
</div>
</div>
</div>
show_modal_click = function(evt){
evt.preventDefault();
var theButton = $(this).attr('href');
var height = $(window).height();
var width = $(window).width();
$('#overlay').fadeToggle("slow");
$('#modal').fadeToggle("slow").css({
'top': height/10,
'left':width/3.5
});
}
/**
* Closes the modal box
*/
close_modal_click = function(evt){
evt.preventDefault();
$('#overlay').fadeToggle("slow");
$('#modal').fadeToggle("slow");
}
$("#modal-close").on("click", close_modal_click);//button that closes the modal box
$("#overlay").on("click", close_modal_click);//closes modal box when clicking on background
/******
modal box
*****/
#overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: black;
opacity: 0.5;
filter: alpha(opacity=50);
display:none;
}
#modal {
position:fixed;
display:none;
}
#content {
#modal-close {
display:inline-block;
width:35px;
height:38px;
position:relative;
top:13px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment