Window-document-javascript
一个浏览器窗口有一个window对象,javascript属于window对象,html为document对象,属于window,body为document对象,只有设置body对象高度为100%,其他地方的高度设置百分比才有效。
html和body本来高度就是0,或者说是auto的。
document.documentElement.offsetHeight,
document.body.offsetHeight都是0
高度根据内容而定,设置为100%就是相对于浏览器窗口window,100%
window.innerHeight与innerWidth获取浏览器窗口内容大小。
做手机Web开发做浏览器兼容用到了,所以在网上找了些汇总下。
alert($(window).height()); //浏览器当前窗口可视区域高度
alert($(document).height()); //浏览器当前窗口文档的高度
alert($(document.body).height());//浏览器当前窗口文档body的高度
alert($(document.body).outerHeight(true));//浏览器当前窗口文档body的总高度 包括border padding margin
alert($(window).width()); //浏览器当前窗口可视区域宽度
alert($(document).width());//浏览器当前窗口文档对象宽度
alert($(document.body).width());//浏览器当前窗口文档body的高度
alert($(document.body).outerWidth(true));//浏览器当前窗口文档body的总宽度 包括border padding margin