﻿/***********************************************************************************
* 功能：得到页面实际尺寸、滚动尺寸、偏移坐标
* 作者：Jack - http://www.kingyar.com
***********************************************************************************/
var Utility = new Object();

//功能: 得到窗口实际宽度
Utility.getWindowWidth = function()
{
	var windowWidth;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
	}	
    
    return windowWidth;
}

//功能: 得到窗口实际高度
Utility.getWindowHeight = function()
{
	var windowHeight;

	if (self.innerHeight) {	// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}	
	
	return windowHeight;
}

//功能：得到页面滚动宽度(窗口宽度+滚动条宽度)
Utility.getScrollWidth = function()
{
	var xScroll;
	
	if (window.innerHeight && window.scrollMaxYX) {	
		xScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
	}

    return xScroll;
}

//功能: 得到页面滚动高度(页面实际高度 + 滚动条高度)
Utility.getScrollHeight = function()
{
	var yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
	}
	
    return yScroll;
}

//功能: 得到页面总高度
Utility.getPageWidth = function()
{
    var xScroll = Utility.getScrollWidth();
    var windowWidth = Utility.getWindowWidth();
    return (xScroll > windowWidth) ? xScroll : windowWidth;
}

//功能: 得到页面总宽度
Utility.getPageHeight = function()
{
    var yScroll = Utility.getScrollHeight();
    var windowHeight = Utility.getWindowHeight();
    return (yScroll > windowHeight) ? yScroll : windowHeight;
}

//得到页面水平滚动偏移
Utility.getScrollX = function()
{
	var xScroll;

	if (self.pageXOffset) {
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollLeft){	 // Explorer 6 Strict
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		xScroll = document.body.scrollLeft;	
	}
	
	return xScroll;
}

//功能: 得到页面垂直滚动偏移坐标
Utility.getScrollY = function()
{

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

	return yScroll;
}
