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

前端 未结 2 430
时光取名叫无心
时光取名叫无心 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

    0 讨论(0)
  • 2020-12-10 03:24

    Maybe you are looking for scrollIntoView method.

    scrollToEl[0].scrollIntoView();
    

    DEMO: http://jsfiddle.net/yuFk5/14/

    0 讨论(0)
提交回复
热议问题