(function ($) {
$.fn.center = function (width, height) {
var objLeft = parseInt(($(window).width() - width) / 2 + $(document).scrollLeft);
var objTop = parseInt(($(window).height() - height) / 2 + $(document).scrollTop);
this[0].style.left = objLeft + 'px';
this[0].style.top = objTop + 'px';
return this;
}
})(jQuery)
//引用 括号内为引用对象的宽度和高度
$('#reg').center(600, 550);