简体   繁体   English

纯javascript中的jquery位置()

[英]jquery position() in plain javascript

I have the following line of code:我有以下代码行:

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

It works great in ie6 and upwards but I also need to get it to work for ie5.5.它在 ie6 及更高版本中运行良好,但我还需要让它适用于 ie5.5。 (Let's not argue about that now - I know - but I have no option) (我们现在不要争论这个 - 我知道 - 但我别无选择)

I'm certain it falls on the .position() while I'm testing on ie5.5 with jquery 1.2我确定它落在 .position() 上,而我正在使用 jquery 1.2 在 ie5.5 上进行测试

How could I do the same in plain javascript?我怎么能在普通的javascript中做同样的事情? Could "offsetParent" help me here? “offsetParent”可以在这里帮助我吗? Apparently ie5.5 supports that.显然ie5.5支持这一点。

Thanks in advance.提前致谢。

You are looking for offsetParent , offsetLeft and offsetRight.您正在寻找offsetParent 、offsetLeft 和 offsetRight。

As you can see in the link, looks like they are supported even by old granny IE5.5.正如您在链接中看到的那样,即使老奶奶 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM