导读:
网窝网版权所有webwoo.net!这里可以修改成你网站的信息 作者:不详 文章来源:互联网
网窝网版权所有webwoo.net!这里可以修改成你网站的信息 在AJAX的运用中,我们可能会经常遇到这样的情况。要动态的创建以个层,而且必须在浏览器的最中央。不管浏览器是否是最大化。这时候我们就必须用到windows和document的几个属性。以下的函数将返回一个包含浏览器的大小和滚动条位置的一个数组。
var getWindowInfo=function()
{
var scrollX=0,scrollY=0,width=0,height=0,contentWidth=0,contentHeight=0;
if(typeof(window.pageXOffset)=='number')
{
scrollX=window.pageXOffset;
scrollY=window.pageYOffset;
}
else if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
{
scrollX=document.body.scrollLeft;
scrollY=document.body.scrollTop;
}
else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))
{scrollX=document.documentElement.scrollLeft;
scrollY=document.documentElement.scrollTop;
}
if(typeof(window.innerWidth)=='number')
{width=window.innerWidth;
height=window.innerHeight;
}
else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
{
width=document.documentElement.clientWidth;
height=document.documentElement.clientHeight;
}
else if(document.body&&(document.body.clientWidth||document.body.clientHeight))
{width=document.body.clientWidth;
height=document.body.clientHeight;
}
if(document.documentElement&&(document.documentElement.scrollHeight||document.documentElement.offsetHeight)){
if(document.documentElement.scrollHeight>document.documentElement.offsetHeight){
contentWidth=document.documentElement.scrollWidth;
contentHeight=document.documentElement.scrollHeight;
}
else
{contentWidth=document.documentElement.offsetWidth;
contentHeight=document.documentElement.offsetHeight;
}}
else if(document.body&&(document.body.scrollHeight||document.body.offsetHeight))
{if(document.body.scrollHeight>document.body.offsetHeight)
{contentWidth=document.body.scrollWidth;
contentHeight=document.body.scrollHeight;
}else{
contentWidth=document.body.offsetWidth;
contentHeight=document.body.offsetHeight;
}
}else
{contentWidth=width;
contentHeight=height;
}
if(height>contentHeight)
height=contentHeight;
if(width>contentWidth)
width=contentWidth;
var rect=new Object();
rect.ScrollX=scrollX;
rect.ScrollY=scrollY;
rect.Width=width;
rect.Height=height;
rect.ContentWidth=contentWidth;
rect.ContentHeight=contentHeight;
return rect;
}
本文转自
http://www.webwoo.net/bc/bencandy-14-14627-1.htm
网窝网版权所有webwoo.net!这里可以修改成你网站的信息 作者:不详 文章来源:互联网
网窝网版权所有webwoo.net!这里可以修改成你网站的信息 在AJAX的运用中,我们可能会经常遇到这样的情况。要动态的创建以个层,而且必须在浏览器的最中央。不管浏览器是否是最大化。这时候我们就必须用到windows和document的几个属性。以下的函数将返回一个包含浏览器的大小和滚动条位置的一个数组。
var getWindowInfo=function()
{
var scrollX=0,scrollY=0,width=0,height=0,contentWidth=0,contentHeight=0;
if(typeof(window.pageXOffset)=='number')
{
scrollX=window.pageXOffset;
scrollY=window.pageYOffset;
}
else if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
{
scrollX=document.body.scrollLeft;
scrollY=document.body.scrollTop;
}
else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))
{scrollX=document.documentElement.scrollLeft;
scrollY=document.documentElement.scrollTop;
}
if(typeof(window.innerWidth)=='number')
{width=window.innerWidth;
height=window.innerHeight;
}
else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
{
width=document.documentElement.clientWidth;
height=document.documentElement.clientHeight;
}
else if(document.body&&(document.body.clientWidth||document.body.clientHeight))
{width=document.body.clientWidth;
height=document.body.clientHeight;
}
if(document.documentElement&&(document.documentElement.scrollHeight||document.documentElement.offsetHeight)){
if(document.documentElement.scrollHeight>document.documentElement.offsetHeight){
contentWidth=document.documentElement.scrollWidth;
contentHeight=document.documentElement.scrollHeight;
}
else
{contentWidth=document.documentElement.offsetWidth;
contentHeight=document.documentElement.offsetHeight;
}}
else if(document.body&&(document.body.scrollHeight||document.body.offsetHeight))
{if(document.body.scrollHeight>document.body.offsetHeight)
{contentWidth=document.body.scrollWidth;
contentHeight=document.body.scrollHeight;
}else{
contentWidth=document.body.offsetWidth;
contentHeight=document.body.offsetHeight;
}
}else
{contentWidth=width;
contentHeight=height;
}
if(height>contentHeight)
height=contentHeight;
if(width>contentWidth)
width=contentWidth;
var rect=new Object();
rect.ScrollX=scrollX;
rect.ScrollY=scrollY;
rect.Width=width;
rect.Height=height;
rect.ContentWidth=contentWidth;
rect.ContentHeight=contentHeight;
return rect;
}
本文转自
http://www.webwoo.net/bc/bencandy-14-14627-1.htm