开发者

jquery offset method doesn't seem to return whole numbers

开发者 https://www.devze.com 2023-01-18 18:18 出处:网络
When using jquery\'s offset method on an element to get its top offset from the document, it returns m开发者_运维知识库e the following for example:

When using jquery's offset method on an element to get its top offset from the document, it returns m开发者_运维知识库e the following for example:

1150.3999938964844

Is there a reason why it does that, and doesn't return a whole number?

Thanks


If it has any dimensions defined as percentages (or any parent does really, unless it's out of the flow) for instance....there's no guarantee it's a whole number :)


Is there a reason why it does that, and doesn't return a whole number?

jQuery.fn.offset = function( options ) {

...

parseFloat( ... )

...
  • jQuery source

See also: Floating Point Accuracy Problems at Wikipedia

0

精彩评论

暂无评论...
验证码 换一张
取 消