js關於可視區高度的一些運算

最近開發用到這幾個API 記錄一下瀏覽器

/*
* 獲取瀏覽器窗口的總高度
*/ 
function getOffsetHeight(){
    return document.documentElement.offsetHeight || document.body.offsetHeight;
}

/*
* 獲取瀏覽器窗口的可視區域的高度
*/ 
function getViewPortHeight() {
    return document.documentElement.clientHeight || document.body.clientHeight;
}
// 獲取瀏覽器窗口垂直滾動條的位置
function getScrollTop() {
    return document.documentElement.scrollTop || document.body.scrollTop;
}
相關文章
相關標籤/搜索