Centering on the viewport

Centering on the viewport

Hi all,<div>
</div><div>I'm in the process of migrating a site from 1.2.7 to 1.3.2.</div><div>
</div><div>So far, I just ran into a bug in webkit browsers that forced me to rewrite "expr1, expr2, ... exprN" selectors into loops (I suppose you're aware of this one).</div>
<div>I also have trouble with attaching event handlers to dynamically created elements, but I guess it's all a question of timing (and probably the correct spot to look into $.live() ).</div><div>
</div><div>Anyway, I had some simple code to get the position for a div to appear at the center of the viewport:</div>
<div>
</div><div><div>    getCenterPosition: function(targetWidth,targetHeight) {</div><div>      var win = $(window);</div><div>      var target = {</div><div>        top: Math.round((win.height()-targetHeight)/2)+win.scrollTop(),</div>
<div>        left: Math.round((win.width()-targetWidth)/2)+win.scrollLeft()</div><div>      }</div><div>      if (target.top<0) target.top = 0;</div><div>      if (target.left<0) target.left = 0;</div><div>      return target;</div>
<div>    },</div><div>
</div><div>It was cross-browser and quite simple indeed.</div><div>
</div><div>Problem is, in 1.3.2, windows dimensions are those of the whole body, not just the viewport. I turned the code upside/down but just can't find the proper mean to do the exact same thing with the changes that probably occured at 1.3.0.</div>
<div>
</div><div>Since you all know the internals of jQuery, I guess this is as good a place to ask for ideas or pointers.</div><div>
</div><div>Take care all,</div><div>
</div><div>-- Julian</div></div>