admin管理员组文章数量:1327939
I have situation similar to the one on image below, where DIV1 have overflow-y: scroll
and one of child divs have class active
. I don't know his position nor the offset from top. How can I find position of child div inside DIV 1 and scroll so far that child with active class is visible.
I don't mind if you use jQuery or plain js. But I prefer jQuery.
I have situation similar to the one on image below, where DIV1 have overflow-y: scroll
and one of child divs have class active
. I don't know his position nor the offset from top. How can I find position of child div inside DIV 1 and scroll so far that child with active class is visible.
I don't mind if you use jQuery or plain js. But I prefer jQuery.
Share Improve this question edited Feb 25, 2013 at 20:54 keeg 3,9769 gold badges50 silver badges101 bronze badges asked Feb 25, 2013 at 20:51 ewooyewooy 2,7215 gold badges32 silver badges53 bronze badges 2- Do you have a list of child divs that you are trying to insert a box-like div around? – Codeman Commented Feb 25, 2013 at 20:56
- @Pheonixblade9 Yes I do – ewooy Commented Feb 25, 2013 at 21:02
1 Answer
Reset to default 5You have to use .position()
method of jQuery. http://api.jquery./position/
Providing your div1
has position: relative
set this method will give you offset from the top-left corner of your div1, so
$('.div1').get(0).scrollTop($('.div1 div.active').position().top);
should do the trick.
本文标签: javascriptDiv offset inside another divStack Overflow
版权声明:本文标题:javascript - Div offset inside another div - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742253135a2441134.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论