Skip to content

Instantly share code, notes, and snippets.

@d33pfri3d
Created August 14, 2012 05:33
Show Gist options
  • Save d33pfri3d/3346618 to your computer and use it in GitHub Desktop.
Save d33pfri3d/3346618 to your computer and use it in GitHub Desktop.
Jquery Center Function
jQuery.fn.center = function() {
_TOP = (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop();
_TOP = (_TOP <= 0) ? 0 : _TOP;
_LEFT= (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft();
_LEFT = (_LEFT <= 0) ? 0 : _LEFT;
this.css({
top:_TOP + "px",
left:_LEFT + "px"
});
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment