1
2
3
4
5
6
7
8
9
10
11
12
13
14
(function(doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
//750 为设计稿宽度 适配rem
recalc = function() {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
clientWidth = clientWidth <= 1080 ? clientWidth : 1080;
docEl.style.fontSize = (clientWidth / 750) * 100 + 'px';
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

       1rem = body 的 px 倍数,按照在 css 中就以设计稿/100 的 rem 来写。
       按照爱疯 6 的 375 宽度来计算,根节点的 font-size 设置为 50px。

       另外,在公共的 css 中设置 body,确保在 PC 上查看页面也不会变形:

1
2
min-width: 320px;
max-width: 640px;