document.documentElement || document.body 是为了消除标准模式和怪异模式之间的差别而做的兼容
document.body.clientWidth ==> BODY 对象宽度
document.body.clientHeight ==> BODY 对象高度
document.documentElement.clientWidth ==> 可见区域宽度
document.documentElement.clientHeight ==> 可见区域高度
- // 获取浏览器窗口的可视区域的宽度
- function getViewPortWidth() {
- return document.documentElement.clientWidth || document.body.clientWidth;
- }
- // 获取浏览器窗口的可视区域的高度
- function getViewPortHeight() {
- return document.documentElement.clientHeight || document.body.clientHeight;
- }
- // 获取浏览器窗口水平滚动条的位置
- function getScrollLeft() {
- return document.documentElement.scrollLeft || document.body.scrollLeft;
- }
- // 获取浏览器窗口垂直滚动条的位置
- function getScrollTop() {
- return document.documentElement.scrollTop || document.body.scrollTop;
- }
来源: http://www.bubuko.com/infodetail-3776870.html