Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery scroll an element to the bottom

Tags:

jquery

scroll

All I can find on the web tells me how to scroll the page to the bottom or to an element.

How is it possible to scroll a specific div which has the style "overflow:auto" to the bottom using jQuery?

like image 388
Ilya Karnaukhov Avatar asked Nov 15 '12 21:11

Ilya Karnaukhov


1 Answers

Yes:

$("#container").scrollTop($("#elementToScrollTo").position().top);​

If you want to go smoothly:

$("#container").animate({
    scrollTop: $("#elementToScrollTo").position().top
}, 1000);

Here, have a fiddle: http://jsfiddle.net/adrianonantua/nxHE8/

like image 91
Adriano Carneiro Avatar answered Sep 28 '22 01:09

Adriano Carneiro