当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 获取页面高度,窗口高度,滚动条高度等参数值getPageSize,getPageScroll

Javascript
Javascript实例教程(12) 隐藏script代码
Javascript实例教程(11) 创建\"后退\"按钮
HTC:浏览器上的舞者
JavaScript 小技巧(第四集)
Javascript实例教程(20) 使用HoTMetal(7)
点一下,首页地址添加到收藏夹(javascript)
Javascript设计漫天雪花
Javascript实例教程(21) OLE Automation(2)
Javascript实例教程(20) 使用HoTMetal(3)
Javascript制作闪烁的边框
JavaScript对象与数组参考大全
Javascript实例教程(21) OLE Automation(3)
利用JavaScript制作倒计时牌
Javascript实例教程(5) 利用Javascript创建对象
利用JAVASCRIPT制作简单动画
Javascript实例教程(15) JS代替CGI
Javascript实例教程(19) 数组
JavaScript[对象.属性]集锦之三
Javascript实例教程(21) OLE Automation(6)
JavaScript 小技巧(第一集)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 132 ::
收藏到网摘: n/a

复制代码 代码如下:

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;
}