【问题标题】:get height for a div with overflow:auto;使用溢出获取 div 的高度:自动;
【发布时间】:2011-03-15 05:13:59
【问题描述】:

我有一个高度:100px 和溢出的 div:auto 内容是动态的。

我想滚动底部的 div

我试过了

$("#chat_content").scrollTop($("#chat_content").height());

但如果内容大于 100px $("#chat_content").height() 返回 100 并且 div 不会在底部滚动

我该怎么办?

谢谢

【问题讨论】:

标签: jquery height scrolltop


【解决方案1】:

试试$("#chat_content").scrollTop($("#chat_content").get(0).scrollHeight);

【讨论】:

    【解决方案2】:

    从底层 DOM 元素中获取 scrollHeight 属性:

    $("#chat_content").scrollTop($("#chat_content").get(0).scrollHeight);
    

    【讨论】:

    • +1 对于滚动高度! :) 旁注:使用$()[0]$().get(0)
    【解决方案3】:

    另一种方法是将内部内容包装在 div 中,然后将“.height”调用更改为

    $("#chat_content").scrollTop($("#chat_content div").height());
    

    【讨论】:

      猜你喜欢
      • 2011-04-11
      • 1970-01-01
      • 2012-10-03
      • 2012-04-04
      • 1970-01-01
      • 1970-01-01
      • 2012-04-26
      • 1970-01-01
      • 2012-06-22
      相关资源
      最近更新 更多