JavaScript-BOM之常用方法兼容ie的封装及其他相关BOM的封装(3)
程序员文章站
2022-04-12 08:05:05
1.获取页面宽高function getViewPortOffset() { if (window.innerHeight) { return { hight: window.innerHeight, width: window.innerWidth } } else { if (document.compatMode == "CSS1Compat") { return...
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;
}
}
本文地址:https://blog.csdn.net/AN27xy/article/details/109389814
上一篇: 前端面试题整合(基础篇)
下一篇: hexo+jithub搭建个人博客