Skip to content

Instantly share code, notes, and snippets.

@cmbirk
Created January 14, 2013 16:24
Show Gist options
  • Save cmbirk/4531252 to your computer and use it in GitHub Desktop.
Save cmbirk/4531252 to your computer and use it in GitHub Desktop.
Center Lightbox with jQuery
//Center Lightbox
function center_box(){
var body = $('body')[0];
var box_height = $('#lightbox').height();
var box_width = $('#lightbox').width();
var screen_height = $(body).height();
var screen_width = $(body).width();
var top = (screen_height / 2) - (box_height / 2);
var left = (screen_width / 2) - (box_width / 2);
$('#lightbox').css('top', top);
$('#lightbox').css('left', left);
}
$(document).ready(function(){
center_box();
});
$(window).resize(function(){
center_box();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment