/*
* Namespace : com.uk.silence.window
* Class: Geometry
* Version : 1.0
*/
var namespace = Module.createNamespace("com.uk.silence.window", 1.0);
namespace.Geometry = (function() {
//浏览器窗口大小及坐上角位置
var Browser = function() {
/*
* 获取浏览器所在位置:
* screenX和screenY需先判断,再判断screenLeft和screenTop
* 原因:在IE9中同时提供screenX,screenY,screenLeft,screenTop.screenX和screenY表示浏览器左上角相对屏幕坐标,screenLeft和screenTop表示浏览器视图区左上角相对屏幕坐标
* IE6,7,8只提供screenLeft和screenTop
* Firefox只提供screenX和screenY
* 在chrome中同时提供screenX,screenY,screenLeft,都表示浏览器左上角相对屏幕坐标
*
* 获取浏览器大小
* IE9,firefox,chrome中提供outerWidth和outerHeight
*
*/
var width = 0, height = 0, left =0, top = 0;
if(window.outerWidth) {
width = window.outerWidth;
height = window.outerHeight;
}
if(window.screenX) {
left = window.screenX;
top = window.screenY;
} else if(window.screenLeft) {
left = window.screenLeft;
top = window.screenTop;
}
return {
"width" : width,
"height" : height,
"position" : {
"left" : left,
"top" : left
}
};
};
//浏览器可视区大小
var Viewport = function(){
var width = 0, height = 0, horizontalScroll = 0, verticalScroll = 0;
if(window.innerWidth) {
width = window.innerWidth;
height = window.innerHeight;
horizontalScroll = window.pageXOffset;
verticalScroll = window.pageYOffset;
} else if(document.documentElement && document.documentElement.clientWidth) {
width = document.documentElement.clientWidth;
height = document.documentElement.clientHeight;
horizontalScroll = document.documentElement.scrollLeft;
verticalScroll = document.documentElement.scrollTop;
} else if(document.body && document.body.clientWidth) {
width = document.body.clientWidth;
height = document.body.clientHeight;
horizontalScroll = document.body.scrollLeft;
verticalScroll = document.body.scrollTop;
}
return {
"width" : width,
"height" : height,
"horizontalScroll" : horizontalScroll,
"verticalScroll" : verticalScroll
};
};
//获取文档大小
var Document = function() {
var width = 0, height = 0;
if(document.documentElement && document.documentElement.scrollWidth) {
width = document.documentElement.scrollWidth;
height = document.documentElement.scrollHeight;
} else if(document.body && document.body.scrollWidth) {
width = document.body.scrollWidth;
height = document.body.scrollHeight;
}
return {
"width" : width,
"height" : height
};
};
//获取滚动条宽度
var Scroll = function() {
var outer = document.createElement("div"),
inner = document.createElement("div"),
barSize = 0;
outer.style.position = "absolute";
outer.style.top = "-1000px";
outer.style.left = "-1000px";
outer.style.width = "100px";
outer.style.height = "100px";
outer.style.margin = "0px";
outer.style.padding = "0px";
outer.style.overflow = "scroll";
document.documentElement.appendChild(outer);
inner.style.position = "relation";
inner.style.border = "0px";
inner.style.height = "200px";
inner.style.margin = "0px";
inner.style.padding = "0px";
outer.appendChild(inner);
barSize = 100 - inner.offsetWidth;
document.documentElement.removeChild(outer);
return {
"barSize" : barSize
};
};
return {
"Browser" : Browser,
"Viewport" : Viewport,
"Document" : Document,
"Scroll" : Scroll
};
})();
* Namespace : com.uk.silence.window
* Class: Geometry
* Version : 1.0
*/
var namespace = Module.createNamespace("com.uk.silence.window", 1.0);
namespace.Geometry = (function() {
//浏览器窗口大小及坐上角位置
var Browser = function() {
/*
* 获取浏览器所在位置:
* screenX和screenY需先判断,再判断screenLeft和screenTop
* 原因:在IE9中同时提供screenX,screenY,screenLeft,screenTop.screenX和screenY表示浏览器左上角相对屏幕坐标,screenLeft和screenTop表示浏览器视图区左上角相对屏幕坐标
* IE6,7,8只提供screenLeft和screenTop
* Firefox只提供screenX和screenY
* 在chrome中同时提供screenX,screenY,screenLeft,都表示浏览器左上角相对屏幕坐标
*
* 获取浏览器大小
* IE9,firefox,chrome中提供outerWidth和outerHeight
*
*/
var width = 0, height = 0, left =0, top = 0;
if(window.outerWidth) {
width = window.outerWidth;
height = window.outerHeight;
}
if(window.screenX) {
left = window.screenX;
top = window.screenY;
} else if(window.screenLeft) {
left = window.screenLeft;
top = window.screenTop;
}
return {
"width" : width,
"height" : height,
"position" : {
"left" : left,
"top" : left
}
};
};
//浏览器可视区大小
var Viewport = function(){
var width = 0, height = 0, horizontalScroll = 0, verticalScroll = 0;
if(window.innerWidth) {
width = window.innerWidth;
height = window.innerHeight;
horizontalScroll = window.pageXOffset;
verticalScroll = window.pageYOffset;
} else if(document.documentElement && document.documentElement.clientWidth) {
width = document.documentElement.clientWidth;
height = document.documentElement.clientHeight;
horizontalScroll = document.documentElement.scrollLeft;
verticalScroll = document.documentElement.scrollTop;
} else if(document.body && document.body.clientWidth) {
width = document.body.clientWidth;
height = document.body.clientHeight;
horizontalScroll = document.body.scrollLeft;
verticalScroll = document.body.scrollTop;
}
return {
"width" : width,
"height" : height,
"horizontalScroll" : horizontalScroll,
"verticalScroll" : verticalScroll
};
};
//获取文档大小
var Document = function() {
var width = 0, height = 0;
if(document.documentElement && document.documentElement.scrollWidth) {
width = document.documentElement.scrollWidth;
height = document.documentElement.scrollHeight;
} else if(document.body && document.body.scrollWidth) {
width = document.body.scrollWidth;
height = document.body.scrollHeight;
}
return {
"width" : width,
"height" : height
};
};
//获取滚动条宽度
var Scroll = function() {
var outer = document.createElement("div"),
inner = document.createElement("div"),
barSize = 0;
outer.style.position = "absolute";
outer.style.top = "-1000px";
outer.style.left = "-1000px";
outer.style.width = "100px";
outer.style.height = "100px";
outer.style.margin = "0px";
outer.style.padding = "0px";
outer.style.overflow = "scroll";
document.documentElement.appendChild(outer);
inner.style.position = "relation";
inner.style.border = "0px";
inner.style.height = "200px";
inner.style.margin = "0px";
inner.style.padding = "0px";
outer.appendChild(inner);
barSize = 100 - inner.offsetWidth;
document.documentElement.removeChild(outer);
return {
"barSize" : barSize
};
};
return {
"Browser" : Browser,
"Viewport" : Viewport,
"Document" : Document,
"Scroll" : Scroll
};
})();