Center Div on div with jQuery

    [javascript]
    // Centers on screen
    jQuery.fn.center = function (div) {
    this.css("position", "absolute");

    var position = div.position();
    this.css("top", Math.max(0, ((div.height() – this.outerHeight()) / 2) + position.top) + "px");

    this.css("left", Math.max(0, ((div.width() – this.outerWidth()) / 2) + position.left) + "px");
    return this;
    };

    //use
    $(‘#ajxload’).center($(‘#mapWrapper’)).show();
    [/javascript]

    Leave a Reply