移动端rem自适应
1 /* 2 手机wap页面retina适配,基于rem; 1rem = 100px(iPhone6) 3 */ 4 ;(function (doc, win) { 5 var docEl = doc.documentElement, 6 resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', 7 recalc = function () { 8 var clientWidth = docEl.clientWidth; 9 if (!clientWidth) return; 10 docEl.style.fontSize = 100 * (clientWidth / 750) + 'px'; //750为设计稿宽度 11 }; 12 13 if (!doc.addEventListener) return; 14 win.addEventListener(resizeEvt, recalc, false); 15 doc.addEventListener('DOMContentLoaded', recalc, false); 16 })(document, window);