获取页面高度,窗口高度,滚动条高度等参数值getPageSize,getPageScroll
获取页面高度,窗口高度,滚动条高度等参数值getPageSize,getPageScroll
发布时间:2016-12-30 来源:查字典编辑
摘要:复制代码代码如下:functiongetPageScroll(){varyScroll;if(self.pageYOffset){yScro...

复制代码 代码如下:

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;

}

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类