index.html 1.3 KB
<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <!-- <link rel="icon" href="<%= BASE_URL %>favicon.ico"> -->
  <title>
    <%= htmlWebpackPlugin.options.title %>
  </title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover">
</head>

<body>
  <noscript>
    <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
        Please enable it to continue.</strong>
  </noscript>
  <div id="app"></div>
  <!-- built files will be auto injected -->
</body>
<script>
  ;
  (function (win) {
    var doc = win.document;
    var docEl = doc.documentElement;
    var tid;
    function refreshRem () {
      var width = docEl.getBoundingClientRect().width;
      if (width > 540) { // 最大宽度
        width = 540;
      }
      var rem = width / 10;
      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();

  })(window);
</script>

</html>