rem计算

 1 (function (win, doc) {
 2       if (!win.addEventListener) return;
 3       var html = document.documentElement;
 4       function setFont() {
 5           var html = document.documentElement;
 6           var k = 720;
 7           html.style.fontSize = html.clientWidth / k * 100 + "px";
 8       }
 9       setFont();
10       setTimeout(function () {
11           setFont();
12       }, 300);
13       doc.addEventListener('DOMContentLoaded', setFont, false);
14       win.addEventListener('resize', setFont, false);
15       win.addEventListener('load', setFont, false);
16 })(window, document);

 

posted @ 2020-11-26 14:37  城里的乡下人  阅读(87)  评论(0编辑  收藏  举报