1. 页面展示相关 Helper
function getPosition(element) {
var rect = element.getBoundingClientRect();
return { x: rect.left, y: rect.top, width: rect.width, height: rect.height };
}
function getViewportSize(w) {
w = w || window;
if ('innerHeight' in w) {
return {
width: w.innerWidth,
height: w.innerHeight,
};
}
var d = w.document;
if (document.compatMode === 'CSS1Compat') {
return {
width: d.documentElement.clientWidth,
height: d.documentElement.clientHeight,
};
}
return {
width: d.body.clientWidth,
height: d.body.clientHeight,
};
}
function getScrollOffset(w) {
w = w || window;
if (w.pageXOffset != null) {
return {
x: w.pageXOffset,
y: w.pageYOffset,
};
}
var d = w.document;
if (d.compatMode === 'CSS1Compat') {
return {
x: d.documentElement.scrollLeft,
y: d.documentElement.scrollTop,
};
}
return {
x: d.body.scrollLeft,
y: d.body.scrollTop,
};
}