Javascript 如何确定滚动高度?

Javascript 如何确定滚动高度?,javascript,jquery,Javascript,Jquery,如何使用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); 谢谢,

如何使用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);
谢谢,

Brian是一个常规的javascript属性,因此不需要jQuery

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

jQuery中的正确方法是-

  • $('#test').prop('scrollHeight')
  • $(“#测试”)[0]。滚动高度
  • $(“#测试”).get(0.scrollHeight
您还可以使用:


$('#test').context.scrollHeight

使用scrollHeight()有什么问题?@BadrHari:jQuery中没有
scrollHeight()
函数。它是$('test').get(0).scrollHeight();谢谢这对我有用:var height=document.getElementById(“chatLog”).scrollHeight-$(“#chatLog”).height();$('#chatLog')。滚动顶部(高度);浏览器支持怎么样?所有主要版本的浏览器都支持它吗?IE8+?@Cupidvogel链接的MDN页面显示IE8++1美元(“#test”)[0]。scrollHeight,因为提问者已经在使用jQuery。这应该是可接受的答案,因为它回答了问题。它应该是可接受的答案。请注意,
prop
方法需要jquery 1.6或更高版本+1从meNote这只返回找到的“第一个”元素的滚动高度,如果任何元素当前“隐藏”,即使其他元素的滚动高度为正,您也可能在这里得到零,FWIW:)@rogerdpack好点先生!虽然在本例中,他使用ID而不是类作为选择器,所以他应该可以,但这一点很好。
prop('scrollHeight')
有效,但
context.scrollHeight
没有:“Message:uncaughttypeError:无法读取未定义的属性'scrollHeight',现在最好不要使用此方法,它在3.0版本中被删除。