Posted in Javascript onFebruary 27, 2010
(function($){ $.fn.center = function(){ var top = ($(window).height() - this.height())/2; var left = ($(window).width() - this.width())/2; var scrollTop = $(document).scrollTop(); var scrollLeft = $(document).scrollLeft(); return this.css( { position : 'absolute', 'top' : top + scrollTop, left : left + scrollLeft } ).show(); } })(jQuery)
调用方法:
$('#dialog').center();
JQuery 将元素显示在屏幕的中央的代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@