tutuzhu 发表于 2013-2-7 14:57:52

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

<!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").offsetHeight;
Firefox、Chrome、Opera : window.innerHeight;
var windowHeight=document.all ? document.getElementsByTagName("html").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();
      }
};



不知道为啥 document.body.scrollTop 赋值以后 ie 火狐 滚动条都能滚到一个位置,谷歌不给滚。。郁闷嫩
页: [1]
查看完整版本: 关于页面高度的一些取值记录