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; }