jQuery를 써서 DIV가 화면 중앙에 나오게 하고싶은데 어떻게 하면 좋을까요?
조회수 2683회
1 답변
-
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; }
이런식으로 함수로 만들어봤습니다.
$(element).center();
이렇게 쓰시면 됩니다.
댓글 입력