关于页面高度的一些取值记录

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
* { margin:0px; padding:0px; }
</style>
</head>
<body>
<div style=" height:200px; ">sfdsadf</div>
</body>
</html>
在body标签 声明标签都齐全的情况下
取的body高度 :
document.body.offsetHeight、document.body.clientHeight 的取值是一样的 都是取 body的高度 alert得到200px
取得可视窗口高度:
ie: document.getElementsByTagName("html")[0].offsetHeight;
Firefox、Chrome、Opera : window.innerHeight;
var windowHeight=document.all ? document.getElementsByTagName("html")[0].offsetHeight : window.innerHeight;
电脑屏幕分辨率高
window.screen.height


var Viewport={
top : function(){
return window.pageYOffset
|| document.documentElement && document.documentElement.scrollTop
|| document.body.scrollTop;
},
height : function(){
return window.innerHeight
|| document.documentElement && document.documentElement.clientHeight
|| document.body.clientHeight;
},
left : function(){
return window.pageXOffset
|| document.documentElement && document.documentElement.scrollLeft
|| document.body.scrollLeft;
},
width : function(){
return window.innerWidth
|| document.documentElement && document.documentElement.clientWidth
|| document.body.clientWidth;
},
right : function(){
return Viewport.left() + Viewport.width();
},
bottom : function(){
return Viewport.top() + Viewport.height();
}
};


//alert(mn.offsetHeight);//260 元素的高度+border
//alert(mn.clientHeight);//240 元素的高度
//alert(mn.offsetWidth);//260 元素的宽度+border
//alert(mn.clientWidth);//240 元素的宽度

//alert(document.body.clientHeight); //等于页面内容的总height 260 如果元素都绝对定位 为0 (如果5个元素 1100)
//alert(document.body.offsetHeight); //等于页面内容的总height+窗口的边线border 260 (如果5个元素 1100)
//alert(document.body.clientWidth); 窗口的可视宽度 随窗口的缩放变动
//alert(document.body.offsetWidth); 窗口的可视宽度+边线border 随窗口的缩放变动

//alert(mn.offsetTop);// 元素的margintop+以上元素的总高度值(总的可视高 不管里面padding或margin)
//alert(mn.offsetLeft);// 元素的marginleft+以左边元素的总高度值(总的可视高 不管里面paddin
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值