
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) 
...{
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
}
else 
...{
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) 
...{
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight) 
...{
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
}
else if (document.body) 
...{
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
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;
} getScrollTop函数获得当前页面的滚动条纵坐标位置。在给页面添加了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
后,document.body.scrollTop永远等于0。此时可以用这个方法来获得scrollTop。
function getScrollTop()
...{
if (typeof window.pageYOffset != 'undefined') 
...{
return window.pageYOffset;
}
else if (typeof document.compatMode != 'undefined' &&
document.compatMode != 'BackCompat') 
...{
return document.documentElement.scrollTop;
}
else if (typeof document.body != 'undefined') 
...{
return document.body.scrollTop;
}
}