jQuery Center Web Page (Vertical and Horizontal)

jQuery code snippet to jQuery Center Web Page or any element both vertically and horizontally. Could be used with an event function to center a Web Page on screen at all times even when the window is resized.

jQuery.fn.center = function() {
  this.css("position", "absolute");
  this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
  this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
  return this;