跨浏览器问题与offset()jquery函数 [英] Cross browser issue with offset() jquery function

查看:190
本文介绍了跨浏览器问题与offset()jquery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个跨浏览器问题与 offset()在jQuery中的函数。例如,我正在寻找锚标记的偏移

I am having a cross browser issue with the offset() function in jQuery. For example, I am looking for the offset of an anchor tag

例如。 $('#anchorid')。offset()。top


    < 3.6 = 205
  • 在IE8 = 204

  • 在IE7 = 553

正如你可以看到每个返回值的区别。我不太关心FF& IE8,但我有IE7和其他人。

As you can see the difference in each returned value. I am not too concerned with the difference between FF & IE8 but I am with IE7 and the others.

有没有另一个功能,我可以使用,将是相同或类似的交叉浏览器或这可能的修复? p>

Is there another function I could use that would be the same or similar cross browsers or a possible fix for this?

推荐答案

有可能是你的标记有错误(非crossbrowser)。

The chances are there is something wrong (non-crossbrowser) with your markup. But as alternative you could try using native javascript instead.

document.getElementById('anchorid').offsetTop

如果你想得到整个页面上的偏移量,你可以使用一个函数:

Of if you wanted to get the offset on the whole page you could use a function like:

function findTotalOffset(obj) {
  var ol = ot = 0;
  if (obj.offsetParent) {
    do {
      ol += obj.offsetLeft;
      ot += obj.offsetTop;
    }while (obj = obj.offsetParent);
  }
  return {left : ol, top : ot};
}

这篇关于跨浏览器问题与offset()jquery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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