jQuery将元素滚动到底部

我在网上找到的所有内容都告诉我如何将页面滚动到底部或元素。

如何使用jQuery将具有“overflow:auto”样式的特定div滚动到底部?

是:

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

如果你想顺利进行:

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

在这里,有一个小提琴: http : //jsfiddle.net/adrianonantua/nxHE8/

演示

 var scr = $('#box')[0].scrollHeight; $('#box').animate({scrollTop: scr},2000); 

您可以滚动顶部,减去窗口高度并添加元素高度。 您的滚动应该到达元素的底部:

 $( 'body' ).animate( { scrollTop: $( '#element' + currentElementId ).offset().top + $( '#element' + currentElementId ).height() - $( window ).height() }, 1000 );