viewport.js 568 B

12345678910111213141516171819
  1. (function (doc, win) {
  2. var docEl = doc.documentElement,
  3. resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
  4. recalc = function () {
  5. var clientWidth = docEl.clientWidth;
  6. if (!clientWidth) return;
  7. var fontSize = 20 * (clientWidth / 375);
  8. if(fontSize > 40) {
  9. fontSize = 40;
  10. }
  11. if(fontSize < 10) {
  12. fontSize = 10;
  13. }
  14. docEl.style.fontSize = fontSize + 'px';
  15. };
  16. if (!doc.addEventListener) return;
  17. win.addEventListener(resizeEvt, recalc, false);
  18. doc.addEventListener('DOMContentLoaded', recalc, false);
  19. })(document, window);