简体   繁体   English

iframe中元素的文档位置

[英]Document position of an element in an iframe

I have some javascript code that uses obj.offsetLeft and obj.offsetTop to get an image position, then hovers an element at that location. 我有一些javascript代码,它们使用obj.offsetLeft和obj.offsetTop来获取图像位置,然后将元素悬停在该位置。 However, long story short, Ive had to embed this html inside an iframe which sits inside a main page. 但是,长话短说,我不得不将这个html嵌入到位于主页内的iframe中。 In IE7, the hover element appears in its correct location fine, until the user scrolls the page. 在IE7中,悬浮元素会正确显示在正确的位置,直到用户滚动页面为止。 As the page is scrolled downwards, the hovered element seems to move downwards also, losing sync with the real position. 当页面向下滚动时,悬停的元素似乎也向下移动,与实际位置失去同步。

I tried using a do while loop to cycle through offsetParent, adding up the offsets. 我尝试使用do while循环在offsetParent中循环,将偏移量加起来。 But this seems to only get as high as the iframe. 但这似乎只能达到iframe的水平。

Is there any other way to accurately retrieve the position of an element inside an iframe, relative to the entire page? 还有其他方法可以准确地检索iframe中相对于整个页面的元素位置吗?

And you can't use some CSS positions to achieve that? 而且您不能使用某些CSS位置来实现这一目标? Otherwise, you have to calculate the iframe position and add it to the positions calculated inside the iframe to get the position "document wise" 否则,您必须计算iframe位置并将其添加到iframe内部计算的位置,以获得“文档明智”的位置

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

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