基于rem去计算适配各种页面
js:
var handlerOrientationChange = function(){
var dpr=window.devicePixelRatio;
var width = (window.innerWidth <= 320) ? 320 : ((window.innerWidth >= 640) ? 640 : window.innerWidth);
var fontSize = 20 * (width / 320) * dpr;
document.documentElement.style.fontSize = fontSize + "px";
};
window.onresize = handlerOrientationChange;
setTimeout(function(){
handlerOrientationChange();
},0)
css:
html{font-size: 20px;}