Jquery - 动态滚动div到底部不起作用的代码

时间:2013-08-02 02:46:00

标签: jquery scroll

本网站提供的大多数解决方案都使用此代码的某些变体向下滚动到div的底部

 $("ol.overflow-element").animate({
      scrollTop: $("ol.overflow-element li:last-child").position().top
 }, 1000);

我在css中有这个

.overflow-element {
    overflow-y: scroll;
    height: 300px;
    padding: 10px;
}

我遇到的问题是它非常不一致。

有时它会正确移动到底部。

但有时它会在靠近顶部或中间的地方滚动。当div已经滚动到底部时,这种情况会一直发生。

出现这种情况的原因是什么?任何其他的,正确的阻碍?

1 个答案:

答案 0 :(得分:4)

div上应用的示例代码如下:

//Scroll to bottom
$('div').animate({scrollTop: $('div').get(0).scrollHeight}, 3000);

//$('div').get(0).scrollHeight - will give the full height of div.
//scrollTop - will be used to animate from the current position to page end.
//3000 - will be the duration.

演示可以在这里找到:http://jsfiddle.net/codebombs/GjXzD/