index.html 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <link rel="icon" href="/favicon.ico" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>金田智慧事业部</title>
  8. <style>
  9. #app {
  10. height: auto;
  11. width: 100%;
  12. }
  13. </style>
  14. <link rel="stylesheet" type="text/css"/>
  15. <script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>
  16. <script src="src/assets/js/plus.js"></script>
  17. <script src="src/assets/js/mui.min.js"></script>
  18. </head>
  19. <body style="margin: 0px; padding: 0px;">
  20. <div id="app"></div>
  21. <script type="module" src="/src/main.js"></script>
  22. <script type="text/javascript">
  23. (function(designWidth, maxWidth) {
  24. var doc = document,
  25. win = window,
  26. docEl = doc.documentElement,
  27. remStyle = document.createElement("style"),
  28. tid;
  29. function refreshRem() {
  30. var width = docEl.getBoundingClientRect().width;
  31. var height=docEl.getBoundingClientRect().height
  32. console.log('宽度',typeof(width))
  33. console.log('高度',height)
  34. console.log(doc)
  35. maxWidth = maxWidth || 1920;
  36. if(!width || width < 1000){
  37. width = 1000
  38. }else if(width > 1920){
  39. width = 1920
  40. }
  41. console.log('宽度2', width)
  42. width > maxWidth && (width = 192000);
  43. var rem = width * 1 / designWidth;
  44. remStyle.innerHTML = 'html{font-size:' + rem + 'px;}';
  45. }
  46. if (docEl.firstElementChild) {
  47. docEl.firstElementChild.appendChild(remStyle);
  48. } else {
  49. var wrap = doc.createElement("div");
  50. wrap.appendChild(remStyle);
  51. doc.write(wrap.innerHTML);
  52. wrap = null;
  53. }
  54. //要等 wiewport 设置好后才能执行 refreshRem,不然 refreshRem 会执行2次;
  55. refreshRem();
  56. win.addEventListener("resize", function() {
  57. clearTimeout(tid); //防止执行两次
  58. tid = setTimeout(refreshRem, 300);
  59. }, false);
  60. win.addEventListener("pageshow", function(e) {
  61. if (e.persisted) { // 浏览器后退的时候重新计算
  62. clearTimeout(tid);
  63. tid = setTimeout(refreshRem, 300);
  64. }
  65. }, false);
  66. if (doc.readyState === "complete") {
  67. doc.body.style.fontSize = "16rem";
  68. } else {
  69. doc.addEventListener("DOMContentLoaded", function(e) {
  70. doc.body.style.fontSize = "16rem";
  71. }, false);
  72. }
  73. })(1920, 192000);
  74. </script>
  75. </body>
  76. </html>