<script>
/* 长宽占位 rem算法, 根据root的rem来计算各元素相对rem, 默认html 320/20 = 16px */
/* 长宽占位 rem算法, 根据root的rem来计算各元素相对rem, 默认html 320/20 = 16px */
function placeholderPic(){
var w = document.documentElement.offsetWidth;
document.documentElement.style.fontSize=w/40+'px';
}
placeholderPic();
window.onresize=function(){
placeholderPic();
}
</script>
代码写在body后面,字体记得用rem填写,类似font-size: 2.7rem;
这样子字体大小跟着屏幕大小变动,
这里还有个参数需要自己调试,就是 document.documentElement.style.fontSize=w/40+'px'; 这里40,你可以随意修改,就知道具体屏幕适配多大字体了。