纯JavaScript的jquery position() [英] jquery position() in plain javascript

查看:60
本文介绍了纯JavaScript的jquery position()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码行:

var newLeftPos = $('span#s' + i).position().left - parseInt($('span#s' + i).css('width'), 10);

它在ie6及更高版本中都很好用,但我还需要使它在ie5.5中起作用. (我们现在不争论这个-我知道-但我别无选择)

It works great in ie6 and upwards but I also need to get it to work for ie5.5. (Let's not argue about that now - I know - but I have no option)

我敢肯定,当我使用jQuery 1.2在ie5.5上进行测试时,它落在了.position()上

I'm certain it falls on the .position() while I'm testing on ie5.5 with jquery 1.2

我该如何在纯JavaScript中做同样的事情? "offsetParent"可以在这里帮助我吗?显然ie5.5支持这一点.

How could I do the same in plain javascript? Could "offsetParent" help me here? Apparently ie5.5 supports that.

谢谢.

推荐答案

您正在寻找 offsetParent ,offsetLeft和offsetRight.

You are looking for offsetParent, offsetLeft and offsetRight.

正如您在链接中看到的那样,即使旧的老奶奶IE5.5也支持它们.

As you can see in the link, looks like they are supported even by old granny IE5.5.

检查此文本页面,以查看您的浏览器是否真正支持它们首先.

Check this text page to see if they are really supported by your browser first.

然后您的函数应该类似于

Then your function should be something like

var span = document.getElementById('s' + i);

var newLeftPos = span.offsetWidth - parseInt(span.style.width);

这篇关于纯JavaScript的jquery position()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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