title: Centering a floating div with jQuery
body: <p>I have just inherited some code and part of that code is to show a floating div and center it.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>function showFloatingDialog(element) {
    removeMessage();
    var height, width;
    var offsetY = $(document).scrollTop();
  
    if (offsetY == undefined) {
      offsetY = 0;
    }
  
    var dialog = $('#' + element);
  
    dialog.show();
  
    height = (($(window).width() - dialog.width()) / 2);
    width = ($(window).height() - dialog.height()) / 2;
    width = width + offsetY;
  
    height = height - 195;
    width = width - 130;
  
    dialog.css('position', 'absolute');
    dialog.css('left', height + 'px');
    dialog.css('top', width + 'px');
  }
  </code></pre>
  
  <p>In its defense, it works perfectly but I the following lines look like a hack:</p>
  
  <pre><code>  width = width + offsetY;
  
    height = height - 195;
    width = width - 130;
  </code></pre>
  
  <p>Is there a better and neater way of getting the same result than this.  </p>