rem.js 773 B

1234567891011121314151617181920212223
  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. // docEl.style.fontSize = 16 * (clientWidth / 375) + 'px';
  8. // };
  9. // if (!doc.addEventListener) return;
  10. // win.addEventListener(resizeEvt, recalc, false);
  11. // doc.addEventListener('DOMContentLoaded', recalc, false);
  12. // })(document, window);
  13. window.onresize = function() {
  14. resize();
  15. }
  16. resize();
  17. function resize() {
  18. var iWidth = $(body).width();
  19. document.getElementsByTagName('html')[0].style.fontSize = 16 * (iWidth / 375) + 'px';
  20. }