Skip to content

Instantly share code, notes, and snippets.

@felipevolpatto
Created September 9, 2015 14:40
Show Gist options
  • Save felipevolpatto/4fa98f775fd9db6e0da0 to your computer and use it in GitHub Desktop.
Save felipevolpatto/4fa98f775fd9db6e0da0 to your computer and use it in GitHub Desktop.
Positioning an element at the center of the actual screen
jQuery.fn.center = function () {
this.css("position","fixed");
this.css("top", ($(window).height() / 2) - (this.outerHeight() / 2));
this.css("left", ($(window).width() / 2) - (this.outerWidth() / 2));
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment