首页 > Web开发 > 详细

Web中的宽和高

时间:2015-11-28 19:56:35      阅读:332      评论:0      收藏:0      [点我收藏+]

不同的宽高定义

//网页可见区域宽
document.body.clientWidth 
//网页可见区域高
document.body.clientHeight 
//网页可见区域宽(包括边线和滚动条的宽) 
document.body.offsetWidth 
//网页可见区域高(包括边线的宽) 
document.body.offsetHeight
//网页正文全文宽
document.body.scrollWidth 
//网页正文全文高
document.body.scrollHeight 
//网页被卷去的高
document.body.scrollTop 
//网页被卷去的左
document.body.scrollLeft 
//网页正文部分上
window.screenTop 
//网页正文部分左
window.screenLeft 
//屏幕分辨率的高
window.screen.height 
//屏幕分辨率的宽
window.screen.width 
//屏幕可用工作区高度
window.screen.availHeight 
//屏幕可用工作区宽度
window.screen.availWidth 
//屏幕设置(位彩色)
window.screen.colorDepth
//屏幕设置(像素/英寸)
window.screen.deviceXDPI 
//BODY对象宽度
document.body.clientWidth
//BODY对象高度
document.body.clientHeight
//可见区域宽度
document.documentElement.clientWidth
//可见区域高度
document.documentElement.clientHeight

 

获取不同宽高的方法

var winWidth;
var winHeight;
// 获取窗口宽度
if (windows.innerWidth)
{
winWidth = windows.innerWidth;
}
else if ((document.body) && (document.body.clientWidth))
{
winWidth = document.body.clientWidth;
}
// 获取窗口高度
if (windows.innerHeight)
{
winHeight = windows.innerHeight;
}
else if ((document.body) && (document.body.clientHeight))
{
winHeight = document.body.clientHeight;
}
// 通过深入 Document 内部对 body 进行检测,获取窗口大小
if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)
{
winHeight = document.documentElement.clientHeight;
winWidth = document.documentElement.clientWidth;
}

 

Web中的宽和高

原文:http://www.cnblogs.com/zcynine/p/5003094.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!