获取页面高度,窗口高度,滚动条高度等参数值
2007-06-02 22:20
369 查看
最近在项目中想实现Div层垂直居中显示,可是无论怎么尝试都无法实现在IE中获得当前Page的高度。后来Google到下面的代码,发现原来是利用document.documentElement.clientHeight,真让人有点莫名其妙。
function getPageScroll(){
var yScroll;
if (self.pageYOffset) {
yScroll = self.pageYOffset;
} else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict
yScroll = document.documentElement.scrollTop;
} else if (document.body) {// all other Explorers
yScroll = document.body.scrollTop;
}
arrayPageScroll = new Array('',yScroll)
return arrayPageScroll;
}
function getPageSize(){
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}
function getPageScroll(){
var yScroll;
if (self.pageYOffset) {
yScroll = self.pageYOffset;
} else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict
yScroll = document.documentElement.scrollTop;
} else if (document.body) {// all other Explorers
yScroll = document.body.scrollTop;
}
arrayPageScroll = new Array('',yScroll)
return arrayPageScroll;
}
function getPageSize(){
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}
相关文章推荐
- 获取页面高度,窗口高度,滚动条高度等参数值getPageSize,getPageScroll
- 获取页面高度,窗口高度,滚动条高度等参数值getPageSize,getPageScroll
- 黄聪:js 获取浏览器、Body、滚动条、可见区域、页面、边框、窗口高度和宽度值(多浏览器)
- jquery 获取浏览器窗口的可视区域高度 宽度 滚动条高
- JS 获取滚动条高度+常用js页面宽度与高度
- 用 Javascript 获取页面大小、窗口大小和滚动条位置
- 转:用 Javascript 获取页面大小、窗口大小和滚动条位置
- js/jquery获取浏览器窗口可视区域高度和宽度以及滚动条高度
- javascript 获取滚动条高度+常用js页面宽度与高度
- 获取页面和滚动条高度的另一种方法
- GetPageSize和GetPageScroll:获取页面大小、窗口大小和滚动条位置
- javascript 获取滚动条高度+常用js页面宽度与高度
- [转] javascript 获取滚动条高度+常用js页面宽度与高度
- JavaScript 获取滚动条高度+常用js页面宽度与高度
- javascript 获取滚动条高度+常用js页面宽度与高度
- js各种获取当前窗口页面宽度、高度的方法
- javascript 获取滚动条高度+常用js页面宽度与高度
- 用 Javascript 获取页面大小、窗口大小和滚动条位置
- javascript 获取滚动条高度+常用js页面宽度与高度(转)
- JS获取各种高度宽度、浏览器窗口滚动条的位置、元素的几何尺寸