为了方便计算都是除100;
页面尺寸字体大小 = (ui尺寸➗100)+ px;
var _hmt = _hmt || [];
;(function(){
//动态计算rem根植的fontSize,以使页面元素根据rem自适应
var XD_Util = {
initRem: function (size) {
size = +size || 100;
var documentElement = window.document.documentElement;
var width = Math.min(documentElement.clientWidth, 750);
documentElement.style.fontSize = width*size /375 + "px";
},
refreshRem: function () {
var _documentElement = window.document.documentElement;
if (_documentElement.clientWidth <= 320) {
_documentElement.style.fontSize = ( 320 / 375 * 100 )+ "px";
} else {
this.initRem();
}
}
};
XD_Util.refreshRem(100);
window.onresize = function(){
XD_Util.refreshRem();
};
})();
网友评论