记录一些简易版本px换算rem的封装方法;根据UI设计稿来换算如:pc端:1920;h5端:750
(function (doc, win) {
let fn = function fn() {
let docEl = doc.documentElement;
let clientWidth = docEl.clientWidth;
if (!clientWidth) return;
docEl.style.fontSize = 100 * (clientWidth / 1920) + 'px';
};
fn();
if (!doc.addEventListener) return;
win.addEventListener('resize', fn);
doc.addEventListener('DOMContentLoaded', fn);
window.CALCULATE_SIZE = function (value) {
return Math.ceil((parseFloat(value) / 1920) * window.innerWidth);
};
})(document, window);