9

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?

4

3 に答える 3

11

はい:

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

スムーズに行きたい場合:

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

ここで、フィドルを持っています: http://jsfiddle.net/adrianonantua/nxHE8/

于 2012-11-15T21:10:47.723 に答える
9

デモ

var scr = $('#box')[0].scrollHeight;
$('#box').animate({scrollTop: scr},2000);
于 2012-11-15T21:16:27.177 に答える