js 获得对象的位置,获取窗口高度/宽度

//获得对象的位置
 function getXY(obj) {
    var o = new Object();
    o.left = 0;
    o.top = 0;
    o.right = 0;
    o.bottom = 0;
    var oWidth = obj.offsetWidth;
    var oHeight = obj.offsetHeight;
    while (obj) {
        o.left += obj.offsetLeft;
        o.top += obj.offsetTop;
        obj = obj.offsetParent;
    }
    o.right = o.left + oWidth;
    o.bottom = o.top + oHeight;
    return o;
}

 

 

// 获取窗口高度
function getWinHeight() {

var winHeight;
 if (window.innerHeight)
  winHeight = window.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;
 }

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

posted @ 2009-11-24 09:45  UI小子  阅读(133)  评论(0)    收藏  举报