欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JavaScript-BOM之常用方法兼容ie的封装及其他相关BOM的封装(3)

程序员文章站 2022-07-03 17:08:22
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