使用js獲取頁面的各種高度


使用js獲取相關高度:

  獲取網頁被滾動條卷去的高度——兼容寫法:

    scrollHeight = documen.body.scrollTop || document.documentElement.scrollTop;

  獲取網頁全文的高度——兼容寫法:

    windowHeight = document.body.scrollHeight || document.documentElement.scrollHeight;

  獲取網頁可視區域的高度——兼容寫法:

    screenHeight = document.body.clientHeight || document.documentElement.clientHeight;

  獲取某個元素的高度——利用DOM對象的屬性http://www.w3school.com.cn/jsref/dom_obj_all.asp

    domHeight = domElement.offsetHeight(包括border和padding)

 

使用jq獲取相關高度:

  獲取網頁被滾動條卷去的高度:

    scrollHeight = $(window).scrollTop();

  獲取網頁全文的高度——兼容寫法:

    windowHeight = $(document).height();

  獲取網頁可視區域的高度——兼容寫法:

    screenHeight = $(window).height();

  獲取某個元素的高度——利用DOM對象的屬性:

    domHeight = domElement.height();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM