rem的js

html {
font-size : 20px;
}
@media only screen and (min- 401px){
html {
font-size: 25px !important;
}
}
@media only screen and (min- 428px){
html {
font-size: 26.75px !important;
}
}
@media only screen and (min- 481px){
html {
font-size: 30px !important;
}
}
@media only screen and (min- 569px){
html {
font-size: 35px !important;
}
}
@media only screen and (min- 641px){
html {
font-size: 40px !important;
}
}

;(function (doc, win, undefined) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in win? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if (clientWidth === undefined) return;
docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
};
if (doc.addEventListener === undefined) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false)
})(document, window);

原文地址:https://www.cnblogs.com/lyk562564104/p/7048011.html