you are here: codestackercodes [RSS]center vertically element

center vertically element

$.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;
};

Comments