获取窗口 高 、宽 的JS代码
上一篇 /
下一篇 2008-04-15 00:06:41
/ 个人分类:转载
vargetViewPortWidth =function()
{
varwidth = 0;
if((document.documentElement) && (document.documentElement.clientWidth))
{
width =document.documentElement.clientWidth;
}
elseif((document.body) && (document.body.clientWidth))
{
width =document.body.clientWidth;
}
elseif(window.innerWidth)
{
width =window.innerWidth;
}
returnwidth;
};
vargetViewPortHeight =function()
{
varheight = 0;
if(window.innerHeight)
{
height =window.innerHeight- 18;
}
elseif((document.documentElement) && (document.documentElement.clientHeight))
{
height =document.documentElement.clientHeight;
}
returnheight;
};
vargetContentHeight =function()
{
if((document.body) && (document.body.offsetHeight))
{
returndocument.body.offsetHeight;
}
return0;
};
vargetViewPortScrollX =function()
{
varscrollX = 0;
if((document.documentElement) && (document.documentElement.scrollLeft))
{
scrollX =document.documentElement.scrollLeft;
}
elseif((document.body) && (document.body.scrollLeft))
{
scrollX =document.body.scrollLeft;
}
elseif(window.pageXOffset)
{
scrollX =window.pageXOffset;
}
elseif(window.scrollX)
{
scrollX =window.scrollX;
}
returnscrollX;
};
vargetViewPortScrollY =function()
{
varscrollY = 0;
if((document.documentElement) && (document.documentElement.scrollTop))
{
scrollY =document.documentElement.scrollTop;
}
elseif((document.body) && (document.body.scrollTop))
{
scrollY =document.body.scrollTop;
}
elseif(window.pageYOffset)
{
scrollY =window.pageYOffset;
}
elseif(window.scrollY)
{
scrollY =window.scrollY;
}
returnscrollY;
};
导入论坛
引用链接
收藏
分享给好友
推荐到圈子
管理
举报
TAG: