移动端适配1px问题

(function(document) {
    var dcl = document.documentElement, wh;
    var scale = 1/window.devicePixelRatio;
    document.querySelector('meta[name="viewport"]').setAttribute('content','initial-scale=' + scale + ', maximum-scale=' + scale + ', minimum-scale=' + scale + ', user-scalable=no');
    function setRootRem() {
        wh = dcl.clientHeight;
        dcl.style.fontSize = 100 * (wh / 1334) + 'px';
    }

    setRootRem();
    document.addEventListener('DOMContentLoaded', setRootRem, false);
    window.addEventListener('resize', setRootRem, false);
})(document);

但是这样会导致在iphone6时输出document.documentElement.clientWidth为750.与传统获取为375不符合。

posted @ 2017-05-05 16:46  黑客PK  阅读(450)  评论(0编辑  收藏  举报