Skip to content

Instantly share code, notes, and snippets.

@riix
Created July 24, 2012 05:27
Show Gist options
  • Save riix/3168215 to your computer and use it in GitHub Desktop.
Save riix/3168215 to your computer and use it in GitHub Desktop.
객체를 화면 중앙에 정렬, Center an element on the Screen with jQuery
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
return this;
}
$(element).center();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment