其他分享
首页 > 其他分享> > rem.js

rem.js

作者:互联网

!(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);

 

标签:function,el,win,addEventListener,js,doc,rem,setSize
来源: https://www.cnblogs.com/hongyumao/p/14337898.html