关于rem适配及vivo手机rem单位不生效

1,286 阅读1分钟

rem适配方式:

(function anonymous() {
    function computed(){
        //let在vivo手机的兼容性有问题,应该使用var
        //https://caniuse.com/#search=text-stroke
        let HTML = document.documentElement||document.body,
            winW = HTML.clientWidth,
            desW = 375;
        console.log(winW);
        if (winW >= 750) {
            HTML.style.fontSize = "200px";
            return ;
        }
        HTML.style.fontSize = winW / desW * 100 + "px";
    }
    computed();
    console.log( document.documentElement.style.fontSize );
    window.addEventListener("resize", computed, false);
})();

出现问题: vivo手机rem单位不生效。

解决方案:

var HTML = document.documentElement||document.body,
            winW = HTML.clientWidth,
            desW = 375;

将let修改为var,可在https://caniuse.com/#search=let查看let兼容性。