jQuerys offset function sometimes returns rati开发者_Python百科onal numbers (like 12.645613) for top or left. I thought that top and left positions are in pixels and so should be integers (there are no half pixel, or?).
Top and left positions can be floating point numbers with any of the units cm, mm, in, pt, pc, em, ex or px, or percentages.
Example:
.someElement { top: 42%; left: 3.14in; }
The offset
function returns the position translated into pixels, so that can very well be a floating point number. The values are not rounded.
With the example given, if the height of the parent would for example be 32 pixels, the top
value of the element would be 32 * 0.42 = 13.44 pixels.
This is an old question, but I guess I could post an answer here, for posterity.
I was having this issue too, and I found out (thanks Firebug) that the problem lies in that the h1 and h3 tags have floating point margins (for instance, Firefox by default gives <H1>
a 0.67em 0
margin).
When you delete the <H1>
and <H3>
tags $(".fixedColumn").eq(0).offset().top
returns an integer. You could just specify margins for those tags and the problem should be fixed.
精彩评论