页面640
公共JS
function initHtmlFontSize(){
var _width = document.body.clientWidth;
_width = _width>640?640:_width;//640/24 = 26.66666666666667
var _fs = _width/26.66666666666667;
//640尺寸的设计图,1rem = 24px,页面所有px都除以24
document.getElementsByTagName("html")[0].style.fontSize = _fs+"px";
}
initHtmlFontSize();
页面750
公共JS
function initHtmlFontSize(){
var _width = document.body.clientWidth;
_width = _width>750?750:_width;//750/30 = 25
var _fs = _width/25;
//750尺寸的设计图,1rem = 30px,页面所有px都除以30
document.getElementsByTagName("html")[0].style.fontSize = _fs+"px";
}
initHtmlFontSize();
rem注意事项,最终HTML的字号不能小于12px,否则页面会出错错位