jQuery中的非整数偏移量位置 [英] Non integer offset positions in jQuery
问题描述
jQuerys偏移函数有时会返回顶部或左侧的有理数(例如12.645613).我认为顶部和左侧的位置都以像素为单位,因此应该是整数(不存在半像素或?).
jQuerys offset function sometimes returns rational 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?).
推荐答案
顶部和左侧位置可以是浮点数,其单位为cm,mm,in,pt,pc,em,ex或px或百分比.
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.
示例:
.someElement { top: 42%; left: 3.14in; }
offset
函数返回转换为像素的位置,因此很可能是浮点数.这些值未四舍五入.
The offset
function returns the position translated into pixels, so that can very well be a floating point number. The values are not rounded.
在给出的示例中,如果父级的高度例如为32像素,则元素的top
值为32 * 0.42 = 13.44像素.
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.
这篇关于jQuery中的非整数偏移量位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!