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)
})
获取的值是不一样的

 

转载于:https://www.cnblogs.com/liujian9527/p/5937893.html

你可能感兴趣的:(document.documentElement.clientHeight 和 $(window).height() 无法正确获取页面可视区高度)