html字体大小随屏幕大小的改变而改变,封装函数如下:
(function(){ ‘use strict‘; setRemUnit(); window.addEventListener(‘resize‘,setRemUnit); function setRemUnit(){ var docEl = document.documentElement; var ratio = 18.75; var viewWidth = docEl.getBoundingClientRect().width || window.innerWidth; docEl.style.fontSize = viewWidth / ratio ‘px‘; } })();