美文网首页
2019-10-17移动端适配方案

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

作者: SherrinfordL | 来源:发表于2019-10-17 14:51 被阅读0次
    //横竖屏分开
    (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);
    

    相关文章

      网友评论

          本文标题:2019-10-17移动端适配方案

          本文链接:https://www.haomeiwen.com/subject/fmammctx.html