jQuery 使用溢出获取 div 的高度:自动;
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3235614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
get height for a div with overflow:auto;
提问by Luca Romagnoli
i have a div with height:100px and overflow:auto the content is dynamic.
我有一个高度为 100px 的 div 和溢出:自动内容是动态的。
i want scroll the div in the bottom
我想滚动底部的 div
i tried with
我试过
$("#chat_content").scrollTop($("#chat_content").height());
but if the content is bigger than 100px $("#chat_content").height() returns 100 and the div isn't scrolled on the bottom
但如果内容大于 100px $("#chat_content").height() 返回 100 并且 div 不会在底部滚动
how can i do?
我能怎么做?
thanks
谢谢
回答by Andy E
Get the scrollHeight
property from the underlying DOM element:
scrollHeight
从底层 DOM 元素获取属性:
$("#chat_content").scrollTop($("#chat_content").get(0).scrollHeight);
回答by Roki
try $("#chat_content").scrollTop($("#chat_content").get(0).scrollHeight);
尝试 $("#chat_content").scrollTop($("#chat_content").get(0).scrollHeight);
回答by dan richardson
Another way is to just wrap the internal content in a div and then just change your ".height" call to
另一种方法是将内部内容包装在 div 中,然后将“.height”调用更改为
$("#chat_content").scrollTop($("#chat_content div").height());