rem.js 597 B

123456789101112131415161718192021
  1. !(function (doc, win) {
  2. var el = doc.documentElement;
  3. //resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
  4. function setSize() {
  5. var w = el.clientWidth;
  6. if (!w) return;
  7. w=w>480?480:w;
  8. w=w<320?320:w;
  9. el.style.fontSize = (100 * (w / 1080)).toFixed(3) + 'px';
  10. }
  11. if (!doc.addEventListener) return;
  12. setSize();
  13. win.addEventListener('resize', setSize, false);
  14. win.addEventListener('pageshow', function(e) {
  15. if (e.persisted) {
  16. setSize();
  17. }
  18. }, false);
  19. })(document, window);