flexible.js 682 B

12345678910111213141516171819
  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. };
  14. if (!doc.addEventListener) return;
  15. win.addEventListener(resizeEvt, recalc, false);
  16. doc.addEventListener('DOMContentLoaded', recalc, false);
  17. }(window, document));