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.
我想做的是得到一个元素被点击的位置相对于元素左上角的坐标.
问题是,在FFX3.6中,jQuery.offset().top
实际上给了我一个十进制值(在IE和Chrome中,这两个值是匹配的).
This fiddle exhibits the issue. If you click the bottom image, jQuery.offset().top
returns 327.5, but offsetTop
returns 328.
我认为offset()
返回了正确的值,我应该使用它,因为它可以跨浏览器工作.然而,人们显然不能点击像素的小数点.确定jQuery返回的偏移量的真正偏移量是正确的方法吗?我应该使用offsetTop
,还是完全使用其他方法?