Send this to a friend
1 $.fn.center = function (relation) {
2 var center_in = (relation) ? $(relation) : $(window);
3
4 this.css("position","absolute");
5 this.css("top", ( center_in.height() - this.height() ) / 2+center_in.scrollTop() + "px");
6 this.css("left", ( center_in.width() - this.width() ) / 2+center_in.scrollLeft() + "px");
7 return this;
8 };
$.fn.center = function (relation) {
var center_in = (relation) ? $(relation) : $(window);
this.css("position","absolute");
this.css("top", ( center_in.height() - this.height() ) / 2+center_in.scrollTop() + "px");
this.css("left", ( center_in.width() - this.width() ) / 2+center_in.scrollLeft() + "px");
return this;
};