js动态获取页面高度


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

$(".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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值