flexible.min.js 1.1 KB

12345678910111213141516171819202122232425
  1. //这段js的最后面有两个参数记得要设置,一个为设计稿实际宽度,一个为制作稿最大宽度,例如设计稿为750,最大宽度为750,则为(750,750)
  2. ! function(e, t) {
  3. function n() {
  4. var n = l.getBoundingClientRect().width;
  5. t = t || 540, n > t && (n = t);
  6. var i = 100 * n / e;
  7. r.innerHTML = "html{font-size:" + i + "px;}"
  8. }
  9. var i, d = document,
  10. o = window,
  11. l = d.documentElement,
  12. r = document.createElement("style");
  13. if (l.firstElementChild) l.firstElementChild.appendChild(r);
  14. else {
  15. var a = d.createElement("div");
  16. a.appendChild(r), d.write(a.innerHTML), a = null
  17. }
  18. n(), o.addEventListener("resize", function() {
  19. clearTimeout(i), i = setTimeout(n, 300)
  20. }, !1), o.addEventListener("pageshow", function(e) {
  21. e.persisted && (clearTimeout(i), i = setTimeout(n, 300))
  22. }, !1), "complete" === d.readyState ? d.body.style.fontSize = "16px" : d.addEventListener("DOMContentLoaded", function(e) {
  23. d.body.style.fontSize = "16px"
  24. }, !1)
  25. }(750, 750);