1.获取页面宽高
function getViewPortOffset() {
if (window.innerHeight) {
return {
hight: window.innerHeight,
width: window.innerWidth
}
} else {
if (document.compatMode == "CSS1Compat") {
return {
hight: document.documentElement.clientHeight,
width: document.documentElement.clientWidth
}
} else {
return {
hight: document.body.clientHeight,
width: document.body.clientWidth
}
}
}
}
2.滚动轮滚动的距离
function getScrollOffset() {
if (window.pageXOffset) {
return {
x: window.pageXOffset,
y: window.pageYOffset
}
} else {
return {
x: document.body.scrollLeft + document.documentElement.scrollLeft,
y: document.body.scrollTop + document.documentElement.scrollTop
}
}
}
3.获取URL地址的参数
function getRequest() {
var tempArray = {};
var strArray = [];
var temp = window.location.search;
if (temp.indexOf("?") != -1) {
var str = temp.substr(1);
strArray = str.split("&");
strArray.forEach(prop => {
tempArray[prop.split("=")[0]] = prop.split("=")[1];
});
return tempArray;
} else {
return null;
}
}