Skip to content

Instantly share code, notes, and snippets.

@slivero
Created September 22, 2011 13:00
Show Gist options
  • Save slivero/1234711 to your computer and use it in GitHub Desktop.
Save slivero/1234711 to your computer and use it in GitHub Desktop.
Add centre() function to jquery to center modals
(function($){
$.fn.extend({
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