开发者

How do I determine scrollHeight?

开发者 https://www.devze.com 2023-04-04 08:14 出处:网络
How do I determine scrollHeight of a division use css overflow:auto? I\'ve tried: $(\'test\').scrollHeight();

How do I determine scrollHeight of a division use css overflow:auto?

I've tried:

$('test').scrollHeight();
$开发者_如何学编程('test').height(); but that just returns the size of the div not all the content

Ultimately, I'm trying to create a chat and always have the scroll bar to the current message on the screen.

So I was thinking something like the following:

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

Thank you,

Brian


Correct ways in jQuery are -

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


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

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


You can also use:

$('#test').context.scrollHeight

0

精彩评论

暂无评论...
验证码 换一张
取 消