Saturday, November 29, 2008

[jQuery] Offset() Shows Different Result On Page Load vs. On Page Resize? Online Demo Provided.

I'm using jQuery's offset() method. I have a function named
ResizeContent that is called on page load, and then is called again
whenever the window is resized. This function includes calls to offset
(). Oddly, I find that offset() is giving me an incorrect value on
page load - but then returns a correct value when the page is resized.

If I watch the offsets using the layout pane in Firebug on Firefox, I
see the exact same anomaly in how the positions of these elements is
reported.

I have placed a demo online at http://tinyurl.com/5w2uke. The results
of offset() are reported in bold via a call to jQuery $(element).text
(). Load the page - look at the numbers reported in bold - then widen
the page - the numbers reported by offset() change, even though the
vertical positions of the elements are unchanged.

What might explain this? Thanks in advance to all for any info.

No comments: