본문 바로가기

JQuery-js-css

[jquery] 화면 center에 오도록 하는 function



jQuery.fn.center = function () {

     this.css("position","absolute");

     this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + 

                                                 $(window).scrollTop()) + "px");

     this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + 

                                                 $(window).scrollLeft()) + "px");

     return this;

}




-호출시

$(아이디 또는 클래스).center();