Skip to content

Instantly share code, notes, and snippets.

@paranoidxc
Created September 3, 2010 07:29
Show Gist options
  • Save paranoidxc/563548 to your computer and use it in GitHub Desktop.
Save paranoidxc/563548 to your computer and use it in GitHub Desktop.
jQuery fn
jQuery.fn.center_v = function () {
this.css("position","absolute");
this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
return this;
}
jQuery.fn.center_h = function () {
this.css("position","absolute");
this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
return this;
}
jQuery.fn.center = function () {
this.css("position","absolute");
this.center_v();
this.center_h();
this.css("z-index","1000101");
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment