document.documentElement.clientHeight 和 $(window).height() 無法正確獲取頁面可視區高度


背景: 彈出層插件(自適應) 實現過程中突然發現在獲取可視區高度時,無論document.documentElement.clientHeight 還是 $(window).height()都無法正確獲取,代碼沒有問題;

解決方案:通過 cosole.log尋找錯誤點發現$(window).height()獲取不正常並等於$(document).height();網上查找資料是由於沒有正確的HTML5文檔聲明導致的

正確:
<!DOCTYPE html> 
    <html>
    <!-- 文檔內容 -->
    </html>
錯誤:
<!DOCTYPE> 
    <html>
    <!-- 文檔內容 -->
    </html>

$(function(){
    console.log($(window).height())
    console.log(document.documentElement.clientHeight)
})
獲取的值是不一樣的

 


免責聲明!

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



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