Skip to content

Instantly share code, notes, and snippets.

@jasdeepkhalsa
Created June 5, 2013 16:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdeepkhalsa/5715402 to your computer and use it in GitHub Desktop.
Save jasdeepkhalsa/5715402 to your computer and use it in GitHub Desktop.
Center function for jQuery
jQuery.fn.center = function() {
this.css({
'position': 'fixed',
'left': '50%',
'top': '50%'
});
this.css({
'margin-left': -this.outerWidth() / 2 + 'px',
'margin-top': -this.outerHeight() / 2 + 'px'
});
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment