1

本网站提供的大多数解决方案都使用此代码的一些变体来向下滚动到 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 已经滚动到底部时,这种情况会始终如一地发生。

为什么会这样?任何替代,正确的实施?

4

1 回答 1

4

应用于 adiv的示例代码如下:

//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/

于 2013-08-02T03:00:29.810 回答