riix
7/24/2012 - 5:27 AM

객체를 화면 중앙에 정렬, Center an element on the Screen with jQuery

객체를 화면 중앙에 정렬, 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();