js动态获取页面高度

来源:互联网 发布:淘宝卖家微淘入口 编辑:程序博客网 时间:2024/05/01 22:39


最近写项目写一个弹框后面的遮罩层。

$(".loading_mask").css({ 

"height": document.documentElement.clientHeight,

 "width":  document.documentElement.clientWidth 

});

看到推酷里面的一位前辈总结的经验:http://www.tuicool.com/articles/mIFvie。

很多时候我们只需要一个结果:

最后,

综上所述,在我们要获取文档实际高度时,最好用document.documentElement.scrollHeight。

在我们要获取视口实际高度时,用document.documentElement.clientHeight。

$(".loading_mask").css({ 

"height":$(document).height()//浏览器当前窗口文档高度

 "width":  $(document).width()

}); 


alert($(window).height()); //浏览器当前窗口可视区域高度

alert($(document).height()); //浏览器当前窗口文档的高度

alert($(document.body).height());//浏览器当前窗口文档body的高度

alert($(document.body).outerHeight(true));//浏览器当前窗口文档body的总高度 包括border padding margin

alert($(window).width()); //浏览器当前窗口可视区域宽度

alert($(document).width());//浏览器当前窗口文档对象宽度

alert($(document.body).width());//浏览器当前窗口文档body的高度

alert($(document.body).outerWidth(true));//浏览器当前窗口文档body的总宽度 包括border padding margin



0 0
原创粉丝点击