Is there anyway to automatically scroll to the first visible element with a certain div class using javascript?
thanks!
The scrollIntoView method: The scrollIntoView() is used to scroll to the specified element in the browser. Example: Using scrollIntoView() to scroll to an element.
How do you make a div scrollable in HTML? For a scrollable bar, use the x and y-axis. Set the overflow-x: hidden; and overflow-y: auto; to automatically hide the horizontal scrollbar and show a vertical scrollbar.
Scrolling to an element can be achieved in Javascript using the scrollIntoView() method. Smooth animation and customizing the alignment can be set through the scrollIntoViewOptions parameter.
You should be able to use something like this:
$('html, body').animate({
scrollTop: $('.class:visible:first').offset().top
}, 1000);
Demo: http://jsfiddle.net/Blender/xUw54/2/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With