one.js 987 B

1234567891011121314151617181920
  1. (function(doc, win) {
  2. var docEl = doc.documentElement, // 获取html对象
  3. resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', // 横屏是否支持,不支持则为浏览器大小改变
  4. // 计算页面字体大小
  5. recalc = function() {
  6. // 获取页面宽度
  7. var clientWidth = docEl.clientWidth;
  8. // 获取不到页面宽度,直接返回
  9. if (!clientWidth) return;
  10. // 设置html字体大小(浏览器默认字体大小为16px)
  11. docEl.style.fontSize = clientWidth / 1920 * 20 + "px";
  12. // console.log(clientWidth / 1920 * 20 + "px")
  13. };
  14. // 不支持addEventListener,返回
  15. if (!doc.addEventListener) return;
  16. // 监听事件,获取当前html标签的字体大小
  17. win.addEventListener(resizeEvt, recalc, false);
  18. // dom内容加在完成事件
  19. doc.addEventListener('DOMContentLoaded', recalc, false);
  20. })(document, window)