Created
January 14, 2013 16:24
-
-
Save cmbirk/4531252 to your computer and use it in GitHub Desktop.
Center Lightbox with jQuery
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
//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