码迷,mamicode.com
首页 > 其他好文 > 详细

rem的计算

时间:2018-03-10 00:17:18      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:app   pix   -name   console   init   hone   agent   span   lis   

(function (doc, win) {

  console.log("dpr:"+win.devicePixelRatio);

  var docEle = doc.documentElement,

  isIos = navigator.userAgent.match(/iphone|ipod|ipad/gi),

  dpr=Math.min(win.devicePixelRatio, 3);

  scale = 1 / dpr,

  resizeEvent = ‘orientationchange‘ in window ? ‘orientationchange‘ : ‘resize‘;

  docEle.dataset.dpr = dpr; var metaEle = doc.createElement(‘meta‘);

  metaEle.name = ‘viewport‘; metaEle.content = ‘initial-scale=‘ + scale + ‘,maximum-scale=‘ + scale;

  docEle.firstElementChild.appendChild(metaEle);

  var recalCulate = function () {

    var width = docEle.clientWidth; if (width / dpr > 640) { width = 640 * dpr; }

    docEle.style.fontSize = 20 * (width / 750) + ‘px‘; };

    recalCulate() if (!doc.addEventListener) return;

     win.addEventListener(resizeEvent, recalCulate, false);

})(document, window);

rem的计算

标签:app   pix   -name   console   init   hone   agent   span   lis   

原文地址:https://www.cnblogs.com/mttcug/p/8536807.html

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