Skip to content Skip to sidebar Skip to footer

How To Scroll Within An Overflow Hidden Div To A Certain Currently Invisible Element?

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. How do I scroll

Solution 1:

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

Solution 2:

Maybe you are looking for scrollIntoView method.

scrollToEl[0].scrollIntoView();

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

Post a Comment for "How To Scroll Within An Overflow Hidden Div To A Certain Currently Invisible Element?"