1.创建rem.js文件,写入代码
(function (doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
docEl.style.fontSize = (clientWidth>=750 ? 100 : clientWidth/7.5) + 'px';//750为设计图宽度,大于750时不会适配
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
2.main.js全局引入
import ‘路径’
3.单位px/100改为rem 如(100px==1rem)