admin管理员组文章数量:1390749
Is There any way to find an element position related to latest relative position parent?
I want a javascript way
assume we have this HTML
<div id="div1" style="position:relative">
<div id="div2" style="padding:10px">
<div id="div3" style="position:absolute top:15px; left:20px;">Stack</div>
</div>
</div>
I want position of "div3" related to "div1".
Thanks
Is There any way to find an element position related to latest relative position parent?
I want a javascript way
assume we have this HTML
<div id="div1" style="position:relative">
<div id="div2" style="padding:10px">
<div id="div3" style="position:absolute top:15px; left:20px;">Stack</div>
</div>
</div>
I want position of "div3" related to "div1".
Thanks
Share Improve this question edited Aug 14, 2016 at 8:23 Mosijava asked Feb 26, 2012 at 15:37 MosijavaMosijava 4,2094 gold badges31 silver badges40 bronze badges 5-
1
You want to find the x/y coordinates of
div3
in relation todiv1
? – David Thomas Commented Feb 26, 2012 at 15:40 -
1
I assume you have tried
.position()
? api.jquery./position – Felix Kling Commented Feb 26, 2012 at 15:43 - yes David, To solve a problem That there is in niceform – Mosijava Commented Feb 26, 2012 at 15:43
- @FelixKling, Is there any java script way? I prefer not to use jQuery – Mosijava Commented Feb 26, 2012 at 15:45
- Ops, I saw it tagged jQuery for some reason :) In any case, you can have look at the source code for this function. It will give you a cross-browser solution (jQuery is JavaScript too ;)), though it might be a bit over the top. – Felix Kling Commented Feb 26, 2012 at 15:46
1 Answer
Reset to default 7div3.offsetTop
and div3.offsetLeft
should fit your requirement(s).
版权声明:本文标题:find position of an element relative to latest relative positioned parent with javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744579644a2613841.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论