【问题标题】:Jquery - Code that dynamically scrolls a div to the bottom not workingJquery - 将div动态滚动到底部的代码不起作用
【发布时间】:2013-08-02 02:46:00
【问题描述】:

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

为什么会出现这种情况?任何替代,正确的实施?

【问题讨论】:

标签: jquery scroll


【解决方案1】:

应用于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/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-27
    • 2016-12-27
    相关资源
    最近更新 更多