rem
程序员文章站
2022-06-05 16:05:39
/** * @example 1rem=100px */!(function (doc, win) { var docEle = doc.documentElement, resizeEvent = 'orientationchange' in window ? 'orientationchange ......
/**
* @example 1rem=100px
*/
!(function (doc, win) {
var docele = doc.documentelement,
resizeevent = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientwidth = docele.clientwidth;
if (!clientwidth) return;
// 750为设计稿尺寸
docele.style.fontsize = clientwidth >= 750 ? '100px' : 100 * (clientwidth / 750) + 'px'
};
if (!doc.addeventlistener) return;
win.addeventlistener(resizeevent, recalc, false);
doc.addeventlistener('domcontentloaded', recalc, false);
})(document, window);