如何确定滚动高度?

如何确定一个除法的 scrollHeight 使用 css overflow: auto?

我试过了:

$('test').scrollHeight();
$('test').height(); but that just returns the size of the div not all the content

最后,我试图创建一个聊天,并始终有滚动条的当前信息在屏幕上。

所以我的想法是这样的:

var test = $('test').height();
$('test').scrollTop(test);

谢谢,

布莱恩

224034 次浏览

scrollHeight is a regular javascript property so you don't need jQuery.

var test = document.getElementById("foo").scrollHeight;

Correct ways in jQuery are -

  • $('#test').prop('scrollHeight') OR
  • $('#test')[0].scrollHeight OR
  • $('#test').get(0).scrollHeight

You can also use:

$('#test').context.scrollHeight

You can try this

$('body')[0].scrollHeight