(function(doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function() {
var clientWidth = docEl.clientWidth;
if (clientWidth > 1920) {
clientWidth = 1920;
}
if (!clientWidth) return;
console.log(clientWidth)
if (clientWidth >= 1225) {
docEl.style.fontSize = 20 * (clientWidth / 1920) + 'px';
} else {
docEl.style.fontSize = 20 * (1225 / 1920) + 'px';
}
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
在html页面引入直接使用