背景: 弹出层插件(自适应) 实现过程中突然发现在获取可视区高度时,无论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)
})
获取的值是不一样的

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-21
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-25
  • 2021-10-19
  • 2021-11-30
相关资源
相似解决方案