7种获取高度的区别

screen.height:用户屏幕高度
screen.availHeight:用户屏幕可用高度,减去了窗口工具值类的界面特征
window.innerHeight:浏览器窗口的视口高度,包括水平滚动条
window.outerHeight:浏览器窗口外部高度
document.body.offsetHeight:文档中 body 部分的高度
document.documentElement.clientHeight:文档可显示区域的高度
document.documentElement.offsetHeight:文档本身的高度(html部分)

示例:

console. log( screen.height); // 768
console. log(screen. availHeight); // 728
console. log (window. innerHeight); // 519
console. log (window. outerHeight) ; // 639
console. log (document. body. offsetHeight) ;// 22
console. log ( document . documentElement . clientHeight); // 519
console. log ( document. documentElement . offsetHeight); // 54

  

原文地址:https://www.cnblogs.com/wangxirui/p/15157234.html