phoneX适配

来源:互联网 发布:mac google搜索打不开 编辑:程序博客网 时间:2024/06/07 02:48
var iphoneCompatibility = (function () {
    return {
        isIphoneX: function () {
            if (window.devicePixelRatio && window.devicePixelRatio == 3 && document.documentElement.clientWidth == 375 && (navigator.userAgent.indexOf("Safari") > -1)) {
                return true
            } else {
                return false
            }
        },
    }
})();
var global_current_viewportHeight = window.innerHeight;
var global_bottom_bar_pannel;
var global_bottom_bar_activity_bar_img;
var global_back_to_top;
window.onscroll = function () {
    if (iphoneCompatibility.isIphoneX()) {
        global_back_to_top = document.querySelector("#mBack2Top");
        global_bottom_bar_pannel = document.querySelector(".bottom-bar-pannel");
        global_bottom_bar_activity_bar_img = document.querySelector(".bottom-bar-activity .bar-img");
        if (window.innerHeight > global_current_viewportHeight) {
            if (global_back_to_top) {
                global_back_to_top.style.bottom = "82px"
            }
            global_bottom_bar_pannel.style.height = "70PX";
            global_bottom_bar_activity_bar_img.style.bottom = "20PX"
        } else {
            if (global_back_to_top) {
                global_back_to_top.style.bottom = "62px"
            }
            global_bottom_bar_pannel.style.transition = ".3s";
            global_bottom_bar_pannel.style.height = "50PX";
            global_bottom_bar_activity_bar_img.style.transition = ".3s";
            global_bottom_bar_activity_bar_img.style.bottom = "0PX"
        }
    }
};
window.onresize = function () {
    if (navigator.userAgent.indexOf("iPhone") > -1 && navigator.userAgent.indexOf("UCBrowser") > -1) {
        var index_search_head = document.getElementById("index_search_head");
        var index_newkeyword = document.getElementById("index_newkeyword");
        if (index_search_head.classList.contains("on-focus")) {
            window.scroll(0, 1)
        } else {
            index_search_head.style.marginTop = 0
        }
    }
};
原创粉丝点击