手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >准确获得页面、窗口高度及宽度的JS
准确获得页面、窗口高度及宽度的JS
摘要:functiongetPageSize(){varxScroll,yScroll;if(window.innerHeight&&window...

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;

}

//forsmallpageswithtotalwidthlessthenwidthoftheviewport

if(xScroll<windowWidth){

pageWidth=windowWidth;

}else{

pageWidth=xScroll;

}

arrayPageSize=newArray(pageWidth,pageHeight,windowWidth,windowHeight)

returnarrayPageSize;

}

有幸找到了你的这个东东,帮我解决了问题,不过仔细看了下,好象大大的有点问题,参数值和名称上看好象有点对不上号哦.

//forsmallpageswithtotalheightlessthenheightoftheviewport

if(yScroll<windowHeight){

pageHeight=yScroll;

}else{

pageHeight=windowHeight;

}

//forsmallpageswithtotalwidthlessthenwidthoftheviewport

if(xScroll<windowWidth){

pageWidth=xScroll;

}else{

pageWidth=windowWidth;

}

【准确获得页面、窗口高度及宽度的JS】相关文章:

获得当前页面URL地址的三个JS代码

根据内容自动调整弹出窗口大小的JS解决方案

Select的OnChange()事件

本窗口将在秒后自动关闭

Java有哪些常用语?Java常用语言汇总

js光标定位文本框回车表单提交问题的解决方法

父窗口获取弹出子窗口文本框的值

在textarea输入Tab

CSS+JS实现点击文字弹出定时自动关闭DIV层菜单的方法

JS实现窗口加载时模拟鼠标移动的方法

精品推荐
分类导航