viewport.js 652 B

12345678910111213141516
  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. // 最大宽度
  8. clientWidth = clientWidth > 640 ? 640 : clientWidth
  9. var fontSize = clientWidth / 7.5;
  10. docEl.style.fontSize = fontSize + 'px';
  11. };
  12. if (!doc.addEventListener) return;
  13. win.addEventListener(resizeEvt, recalc, false);
  14. doc.addEventListener('DOMContentLoaded', recalc, false);
  15. })(document, window);