欢迎来到福编程网,本站提供各种互联网专业知识!

准确获得页面、窗口高度及宽度的JS

发布时间:2006-11-26 作者: 来源:转载
functiongetPageSize(){varxScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=document.body.scrollWidth;yScroll=window.innerHeight+window.scrollMaxY;}elseif(document.body.scrollHeight>document.body.offsetHeight){//allbutExplore
functiongetPageSize(){

varxScroll,yScroll;

if(window.innerHeight&&window.scrollMaxY){
xScroll=document.body.scrollWidth;
yScroll=window.innerHeight+window.scrollMaxY;
}elseif(document.body.scrollHeight>document.body.offsetHeight){//allbutExplorerMac
xScroll=document.body.scrollWidth;
yScroll=document.body.scrollHeight;
}else{//ExplorerMac...wouldalsoworkinExplorer6Strict,MozillaandSafari
xScroll=document.body.offsetWidth;
yScroll=document.body.offsetHeight;
}

varwindowWidth,windowHeight;
if(self.innerHeight){//allexceptExplorer
windowWidth=self.innerWidth;
windowHeight=self.innerHeight;
}elseif(document.documentElement&&document.documentElement.clientHeight){//Explorer6StrictMode
windowWidth=document.documentElement.clientWidth;
windowHeight=document.documentElement.clientHeight;
}elseif(document.body){//otherExplorers
windowWidth=document.body.clientWidth;
windowHeight=document.body.clientHeight;
}

//forsmallpageswithtotalheightlessthenheightoftheviewport
if(yScrollpageHeight=windowHeight;
}else{
pageHeight=yScroll;
}

//forsmallpageswithtotalwidthlessthenwidthoftheviewport
if(xScrollpageWidth=windowWidth;
}else{
pageWidth=xScroll;
}


arrayPageSize=newArray(pageWidth,pageHeight,windowWidth,windowHeight)
returnarrayPageSize;
}
有幸找到了你的这个东东,帮我解决了问题,不过仔细看了下,好象大大的有点问题,参数值和名称上看好象有点对不上号哦.
//forsmallpageswithtotalheightlessthenheightoftheviewport
if(yScrollpageHeight=yScroll;
}else{
pageHeight=windowHeight;
}

//forsmallpageswithtotalwidthlessthenwidthoftheviewport
if(xScrollpageWidth=xScroll;
}else{
pageWidth=windowWidth;
}

相关推荐