Created
August 14, 2013 15:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****** | |
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