Skip to content

Instantly share code, notes, and snippets.

@codylindley
Created July 21, 2010 20:33
Show Gist options
  • Save codylindley/485077 to your computer and use it in GitHub Desktop.
Save codylindley/485077 to your computer and use it in GitHub Desktop.
(function ($) {
$.fn.center = function () {
return this.each(function () {
var top = ($(window).height() - $(this).outerHeight()) / 2;
var left = ($(window).width() - $(this).outerWidth()) / 2;
$(this).css({
position: 'absolute',
margin: 0,
top: (top > 0 ? top : 0) + 'px',
left: (left > 0 ? left : 0) + 'px'
});
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment