2019-10-17移动端适配方案

2019-10-17  本文已影响0人  SherrinfordL
//横竖屏分开
(function (win, doc) {
    if (!win.addEventListener) return;
    var html = document.documentElement;

    function setFont() {
        var html = document.documentElement;
        var k = 750;
        html.style.fontSize = html.clientWidth / k * 100 + "px";
    }

    setFont();
    setTimeout(function () {
        setFont();
    }, 300);
    doc.addEventListener('DOMContentLoaded', setFont, false);
    win.addEventListener('resize', setFont, false);
    win.addEventListener('load', setFont, false);
})(window, document);
// 适配PC端
// if (!/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
//     window.location.href = "/cp/20190724download/index.html"+location.search;
// }

// 横竖屏共用
(function (win, doc) {
    if (!win.addEventListener) return;
    function setFont() {
        var html = document.documentElement;
        var k = (html.clientWidth > html.clientHeight) ? 1334 : 750;
        html.style.fontSize = html.clientWidth / k * 100 + "px";
    }
    setFont();
    setTimeout(function () {
        setFont();
    }, 300);
    doc.addEventListener('DOMContentLoaded', setFont, false);
    win.addEventListener('resize', setFont, false);
    win.addEventListener('load', setFont, false);
})(window, document);
上一篇下一篇

猜你喜欢

热点阅读