移动端随笔

通过HTML5开发的APP,退出应用的代码

  plus.runtime.quit();

针对不同分辨率计算font-size

  监听浏览器更改 html的font-size

(function (doc, win) {
  var docEl = doc.documentElement,
    resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
    recalc = function () {
      var clientWidth = docEl.clientWidth;
      if (!clientWidth) return;
      docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
    };

  if (!doc.addEventListener) return;
  win.addEventListener(resizeEvt, recalc, false);
  doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

js 处理响应式 px 转换 rem

~ function(desW) {
    var winW = document.documentElement.clientWidth;
    if(winW > desW) {
        var oMain = document.querySelector(".box");
        oMain.style.margin = "0 auto";
        oMain.style.width = desW + "px";
        return;
    }
    document.documentElement.style.fontSize = winW / desW * 100 + "px";
}(640);

在线 px 转换 rem 工具地址:http://520ued.com/tools/rem

程序员在线工具

  链接地址http://www.ofmonkey.com/tools/front#rem

原文地址:https://www.cnblogs.com/fanyz/p/7086522.html