Skip to content

Instantly share code, notes, and snippets.

@eboyer
Created July 25, 2011 21:26
Show Gist options
  • Save eboyer/1105275 to your computer and use it in GitHub Desktop.
Save eboyer/1105275 to your computer and use it in GitHub Desktop.
Shaun Crittenden Modals
concentrated.modals = function(btn,modal){
var $btn = $(btn);
var $modal = $(modal);
var $overlay = $('#overlay');
var $close = $('a.close', $modal);
// set overlay height
var docHeight = $(document).height();
$overlay.css({ height : docHeight });
// open link
$btn.each(function(){
$(this).click(function(e){
e.preventDefault();
var $url = $(this).attr("href");
$overlay.fadeTo('fast',.9,function(){
//populate modal
$modal.load($url);
// center modal
$modal.css("top", ($(window).height() - 600) / 2+$(window).scrollTop() + "px");
$modal.css("left", ($(window).width() - $modal.width() ) / 2+$(window).scrollLeft() + "px");
//fade in modal
$modal.fadeIn('slow');
});
});
});
// overlay close
$overlay.click(function(){
$modal.fadeOut('slow',function(){
$overlay.fadeOut('fast');
$modal.html("");
});
});
// close
$close.live("click", function(e){
e.preventDefault();
$modal.fadeOut('slow',function(){
$overlay.fadeOut('fast');
$modal.html("");
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment