$(window).height();指的是浏览器窗口的高度
$(document).height();指的是整个网页的高度
$(window).scrollTop();指的是浏览器窗口顶端距离网页顶端的距离
当网页高度不足浏览器窗口时$(document).height()返回的是$(window).height()。
例:
<pre class="html" name="code"><div style="border:1px solid black;width:200px;height:200px;overflow:auto">
This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text..
</div><script type="text/javascript">$(document).ready(function(){ $(".btn1").click(function(){ alert($("div").scrollTop()+" px"); });});</script>
不建议使用$("html").height()、$("body").height()这样的高度。
原因:
$("body").height():body可能会有边框,获取的高度会比$(document).height()小;
$("html").height():在不同的浏览器上获取的高度的意义会有差异,说白了就是浏览器不兼容。
本文介绍了如何使用jQuery来获取浏览器窗口的高度、整个网页的高度以及浏览器窗口顶端距离网页顶端的距离等关键信息。
823

被折叠的 条评论
为什么被折叠?



