offsetTop vs. jQuery.offset()。top [英] offsetTop vs. jQuery.offset().top

查看:122
本文介绍了offsetTop vs. jQuery.offset()。top的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读过 offsetLeft offsetTop 在所有浏览器中无法正常工作。 jQuery.offset()应该为此提供一个抽象,以提供正确的值xbrowser。

I have read that offsetLeft and offsetTop do not work properly in all browsers. jQuery.offset() is supposed to provide an abstraction for this to provide the correct value xbrowser.

我是什么我想要做的是获取相对于元素左上角点击元素的坐标。

What I am trying to do is get the coordinates of where an element was clicked relative to the top-left of the element.

问题是 jQuery。 offset()。top 实际上是在FFX 3.6中给我一个十进制值(在IE和Chrome中,两个值匹配)。

Problem is that jQuery.offset().top is actually giving me a decimal value in FFX 3.6 (in IE and Chrome, the two values match).

< a href =http://jsfiddle.net/htCPp/> http://jsfiddle.net/htCPp/ 展示了这个问题。如果单击底部图像, jQuery.offset()。top 返回327.5,但 offsetTop 返回328。

http://jsfiddle.net/htCPp/ exhibits the issue. If you click the bottom image, jQuery.offset().top returns 327.5, but offsetTop returns 328.

我想认为 offset()返回正确的值我应该使用它因为它可以工作浏览器。但是,人们显然无法点击像素的小数。是否正确的方法来确定 Math.Round()的真实偏移量 jQuery返回的偏移量?我应该使用 offsetTop ,还是完全使用其他方法?

I would like to think that offset() is returning the correct value and I should use it because it will work across browsers. However, people obviously cannot click decimals of pixels. Is the proper way to determine the true offset to Math.Round() the offset that jQuery is returning? Should I use offsetTop instead, or some other method entirely?

推荐答案

我认为你是对的,说人们不能点击半像素,所以个人而言,我会使用舍入的jQuery偏移......

I think you are right by saying that people cannot click half pixels, so personally, I would use rounded jQuery offset...

这篇关于offsetTop vs. jQuery.offset()。top的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆