jQuery centering div to window vertically resizing issue
<p>I am using this method to center a div vertically on my page:</p>

<pre><code>$(window).resize(function() {
    $('.container').css({
        top : ($(window).height() - $('.container').outerHeight()) / 2
    });
});
$(window).resize();
</code></pre>

<p>But the code doesn't work initially. I couldn't figure out what was going on until I tried physically resizing the window while the page is loading. As soon as I physically resize the browser window, the div centered immediately. Any way around this? Why is that happening in the first place?</p>

<p>Thanks!</p>
