Fn.js 668 B

123456789101112131415161718192021
  1. (function (doc, win) {
  2. const uiWidth = 1920; // 设计稿宽度
  3. const docEl = doc.documentElement;
  4. const resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
  5. const recalc = function () {
  6. let clientWidth = docEl.clientWidth;
  7. if (!clientWidth) {
  8. return;
  9. }
  10. // if (clientWidth >= uiWidth) {
  11. // clientWidth = uiWidth;
  12. // }
  13. docEl.style.fontSize = 100 * (clientWidth / uiWidth) + 'px';
  14. };
  15. if (!doc.addEventListener) {
  16. return;
  17. }
  18. win.addEventListener(resizeEvt, recalc, false);
  19. doc.addEventListener('DOMContentLoaded', recalc, false);
  20. recalc();
  21. })(document, window);