html字体自适应

!(function (doc, win) {
var el = doc.documentElement;//html
//resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';

//设置html的字体
function setSize() {
var w = el.clientWidth;
if (!w) return;
w=w>480?480:w;
w=w<320?320:w;
el.style.fontSize = (100 * (w / 1080)).toFixed(3) + 'px';
}
if (!doc.addEventListener) return;
setSize();
win.addEventListener('resize', setSize, false);
win.addEventListener('pageshow', function(e) {
if (e.persisted) {
setSize();
}
}, false);
})(document, window);

 

posted @ 2021-01-12 16:47  红羽毛学习站  阅读(410)  评论(1编辑  收藏  举报