码迷,mamicode.com
首页 > 移动开发 > 详细

移动端rem设置(部分安卓机型不兼容)

时间:2018-01-23 18:20:38      阅读:1357      评论:0      收藏:0      [点我收藏+]

标签:width   var   bsp   ges   部分   win   idt   console   doc   

(function(win) {
      var doc = win.document;
      var docEl = doc.documentElement;
      var tid;
      function refreshRem() {
          var width = docEl.getBoundingClientRect().width;
          if (width > 640) { // 最大宽度
              width = 640;
          }
          var rem = width / 10; // 将屏幕宽度分成10份, 1份为1rem
          docEl.style.fontSize = rem + ‘px‘;
      }
      win.addEventListener(‘resize‘, function() {
          clearTimeout(tid);
          tid = setTimeout(refreshRem, 300);
      }, false);
      win.addEventListener(‘pageshow‘, function(e) {
          if (e.persisted) {
              clearTimeout(tid);
              tid = setTimeout(refreshRem, 300);
          }
      }, false);
      refreshRem();
      console.log(docEl.style.fontSize)
})(window);

 

移动端rem设置(部分安卓机型不兼容)

标签:width   var   bsp   ges   部分   win   idt   console   doc   

原文地址:https://www.cnblogs.com/gzh529/p/8336953.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!