您的位置:首页 > Web前端 > JavaScript

js动态获取页面高度

2016-05-31 14:36 393 查看
最近写项目写一个弹框后面的遮罩层。

$(".loading_mask").css({ 

"height": document.documentElement.clientHeight,

 "width":  document.documentElement.clientWidth 

});


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

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

最后,



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

在我们要获取视口实际高度时,用document.documentElement.clientHeight。
$(".loading_mask").css({ 

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

 "width":  [b]$(document).width()[/b]

}); 



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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  web前端 工作