baniol
5/17/2014 - 6:41 AM

center box, jquery plugin

center box, jquery plugin

/**
  * jQuery utility for centering a div on the screen
  *
  * @static
  * @method $.centerBox
  */
  $.fn.centerBox = function () {
    var t = this;
    t.css("top", Math.max(0, (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop()) + "px");
    t.css("left", Math.max(0, (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft()) + "px");
    return t;
  };