欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS 獲取頁面尺寸的方法詳解

 更新時(shí)間:2023年09月05日 08:35:06   作者:編程三昧  
通過 JS 獲取頁面相關(guān)的尺寸是比較常見的操作,尤其是在動(dòng)態(tài)計(jì)算頁面布局時(shí),今天我們就來學(xué)習(xí)一下幾個(gè)獲取頁面尺寸的基本方法,需要的朋友可以參考下

獲取頁面高度

function getPageHeight() {
  var g = document,
    a = g.body,
    f = g.documentElement,
    d = g.compatMode == "BackCompat" ? a : g.documentElement;
  return Math.max(f.scrollHeight, a.scrollHeight, d.clientHeight);
}

獲取頁面scrollLeft

function getPageScrollLeft() {
  var a = document;
  return a.documentElement.scrollLeft || a.body.scrollLeft;
}

獲取頁面scrollTop

function getPageScrollTop() {
  var a = document;
  return a.documentElement.scrollTop || a.body.scrollTop;
}

獲取頁面可視寬度

function getPageViewWidth() {
  var d = document,
    a = d.compatMode == "BackCompat" ? d.body : d.documentElement;
  return a.clientWidth;
}

獲取頁面可視高度

function getPageViewHeight() {
  var d = document,
    a = d.compatMode == "BackCompat" ? d.body : d.documentElement;
  return a.clientHeight;
}

獲取頁面寬度

function getPageWidth() {
  var g = document,
    a = g.body,
    f = g.documentElement,
    d = g.compatMode == "BackCompat" ? a : g.documentElement;
  return Math.max(f.scrollWidth, a.scrollWidth, d.clientWidth);
}

到此這篇關(guān)于JS 獲取頁面尺寸的方法詳解的文章就介紹到這了,更多相關(guān)JS獲取頁面尺寸內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論