rem

作者: 嘤夏影 | 来源:发表于2018-09-14 10:57 被阅读14次
(function () {
    var vWidth = (window.document.documentElement.getBoundingClientRect().width > 750) ? 750 :                     window.document.documentElement.getBoundingClientRect().width;
    if (vWidth > 320) {
        window.document.documentElement.style.fontSize = vWidth / 7.5 + "px";
    } else {
        window.document.documentElement.style.fontSize = 320 / 7.5 + "px";
    }
})();
window.onresize = function () {
    var vWidth = (window.document.documentElement.getBoundingClientRect().width > 750) ? 750 :     window.document.documentElement.getBoundingClientRect().width;
    if (vWidth > 320) {
        window.document.documentElement.style.fontSize = vWidth / 7.5 + "px";
    } else {
        window.document.documentElement.style.fontSize = 320 / 7.5 + "px";
    }
}

引入上面的js,在设置宽高的时候只要将量出来的宽高除以100即可哦
比如 100px就是1rem哦

相关文章

网友评论

      本文标题:rem

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