flexible.js 786 B

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