码迷,mamicode.com
首页 > Windows程序 > 详细

document.documentElement.clientHeight 和 $(window).height() 无法正确获取页面可视区高度

时间:2016-10-08 13:29:24      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

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

 

document.documentElement.clientHeight 和 $(window).height() 无法正确获取页面可视区高度

标签:

原文地址:http://www.cnblogs.com/liujian9527/p/5937893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!