javascript - Div offset inside another div - Stack Overflow

I have situation similar to the one on image below, where DIV1 have overflow-y: scroll and one of child

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
Add a ment  | 

1 Answer 1

Reset to default 5

You 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742253136a4409528.html

相关推荐

  • javascript - Div offset inside another div - Stack Overflow

    I have situation similar to the one on image below, where DIV1 have overflow-y: scroll and one of child

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信