Skip to content

Instantly share code, notes, and snippets.

@adanzilla
Last active August 29, 2015 14:24
Show Gist options
  • Save adanzilla/f902e3cda6c534ade879 to your computer and use it in GitHub Desktop.
Save adanzilla/f902e3cda6c534ade879 to your computer and use it in GitHub Desktop.
jQuery - Función Center
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", Math.max(0, ((jQuery(window).height() - jQuery(this).outerHeight()) / 2) + jQuery(window).scrollTop()) + "px");
this.css("left", Math.max(0, ((jQuery(window).width() - jQuery(this).outerWidth()) / 2) + jQuery(window).scrollLeft()) + "px");
return this;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment