rem.js 426 B

123456789101112131415161718
  1. (function(){
  2. function w() {
  3. var r = document.documentElement;
  4. var a = r.getBoundingClientRect().width;
  5. if (a > 750 ){
  6. a = 750;
  7. }
  8. //750/w = 100/font-size
  9. rem = a / 7.5;
  10. r.style.fontSize = rem + "px"
  11. }
  12. var t;
  13. w();
  14. window.addEventListener("resize", function() {
  15. clearTimeout(t);
  16. t = setTimeout(w, 300);
  17. }, false);
  18. })();