如何获取文档的滚动位置?
如何获取文档的滚动位置值?
$(document).height() //returns window height $(document).scrollTop() //returns scroll position from top of document  以下是如何获取使用jQueryselect器获得的元素的scrollHeight : 
 $(selector)[0].scrollHeight 
 如果selector是元素的id(例如elemId ),那么保证数组的0索引项是你想要select的元素,而scrollHeight将是正确的。 
如果您使用Jquery 1.6或更高版本,请使用prop来访问该值。
 $(document).prop('scrollHeight') 
以前的版本用于从attr中获取值,但不能在1.6版本之后。
 document.getElementById("elementID").scrollHeight $("elementID").scrollHeight 
它使用HTML DOM元素,但不使用jQueryselect器。 它可以用来像:
 var height = document.body.scrollHeight; 
像这样的东西应该可以解决你的问题:
 $.getDocHeight = function(){ var D = document; return Math.max(Math.max(D.body.scrollHeight, D.documentElement.scrollHeight), Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), Math.max(D.body.clientHeight, D.documentElement.clientHeight)); }; alert( $.getDocHeight() ); 
Ps:每次需要时调用该函数,警报用于testing目的。
 为了得到窗口滚动条滚动区域的实际可滚动高度,我使用了$('body').prop('scrollHeight') 。 这似乎是最简单的工作解决scheme,但我没有广泛检查兼容性。  Emanuele Del Grande注意到另一个解决scheme,这可能不适用于低于8的IE浏览器。 
 大多数其他解决scheme适用于可滚动元素,但是这适用于整个窗口。 值得注意的是,我和Ankit的解决scheme有Michael一样的问题,即$(document).prop('scrollHeight')返回undefined 。 
你可以尝试这个例子,这个代码把滚动条放在所有DIV标签的底部
记住:jQuery可以接受一个函数,而不是值作为参数。 “this”是jQuery处理的对象,函数返回当前DIV“this”的scrollHeight属性,并为文档中的所有DIV执行此操作。
 $("div").scrollTop(function(){return this.scrollHeight}) 
尝试这个:
 var scrollHeight = $(scrollable)[0] == document ? document.body.scrollHeight : $(scrollable)[0].scrollHeight;