获取页面高度,窗口高度,滚动条高度等参数值getPageSize,getPageScroll

时间:2021-05-18

复制代码 代码如下:
functiongetPageScroll(){
varyScroll;
if(self.pageYOffset){
yScroll=self.pageYOffset;
}elseif(document.documentElement&&document.documentElement.scrollTop){//Explorer6Strict
yScroll=document.documentElement.scrollTop;
}elseif(document.body){//allotherExplorers
yScroll=document.body.scrollTop;
}

arrayPageScroll=newArray('',yScroll)
returnarrayPageScroll;
}

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(yScroll<windowHeight){
pageHeight=windowHeight;
}else{
pageHeight=yScroll;
}

if(xScroll<windowWidth){
pageWidth=windowWidth;
}else{
pageWidth=xScroll;
}

arrayPageSize=newArray(pageWidth,pageHeight,windowWidth,windowHeight)
returnarrayPageSize;
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章