How to scroll within an overflow hidden div to a certain currently invisible element?

前端 未结 2 434
时光取名叫无心
时光取名叫无心 2020-12-10 03:05

I have a list of elements within a overflow hidden div. So not all elements are visible. Now, if an element gets activated, it should become visible within the div.

2条回答
  •  旧巷少年郎
    2020-12-10 03:10

    You can set the scrollTop of the wrapper div to be the top of the position of the active element.

    $("#wrapper").scrollTop($("#wrapper").scrollTop() + $("div.element.active").position().top);
    

    DEMO

提交回复
热议问题