8、关于窗口和文档的几个重要的高度

1、文档区域的高度

 
document.body.clientHeight

2、窗口可视化区域的高度和宽度

   
document.documentElement.clientHeight
document.documentElement.clientWidth


3、窗口的总高度

document.documentElement.scrollHeight


4、窗口已滚动的高度    

[*]几乎所有浏览器都支持用document.documentElement.scrollTop来获取网页的滚动高度,除了Chrome和Safari
[*]只有Chrome和Safari支持用document.body.scrollTop来获取网页的高度
[*]通过获取document.documentElement.scrollTop和document.body.scrollTop两者之间较大值为网页的真实滚动高度

 
document.documentElement.scrollTop 
document.body.scrollTop

5、得到窗口已滚动的高度,并显示在document.title上


<script type="text/javascript">
	window.onscroll = function() {
		var topValue1 = document.documentElement.scrollTop;
		var topValue2 = document.body.scrollTop;
		var topValue = topValue1 > topValue2 ? topValue1 : topValue2;
		document.title = topValue;
	}
</script>

你可能感兴趣的:(文档区域的高度,窗口可视化区域的高度和宽度,窗口已滚动的高度,窗口的总高度)