index.ts 916 B

12345678910111213141516171819
  1. // 设置根节点html的字体大小用于移动端适配使用
  2. export const setHtmlFontSize = () => {
  3. console.count("setHtmlFontSize");
  4. (function (doc, win) {
  5. var htmlDom = doc.getElementsByTagName("html")[0],
  6. resizeEvt = "orientationchange" in win ? "orientationchange" : "resize",
  7. recalc = function () {
  8. requestAnimationFrame(() => {
  9. var clientWidth = doc.documentElement.clientWidth || doc.body.clientWidth;
  10. if (!clientWidth) return;
  11. htmlDom.style.fontSize = clientWidth>=578.88 ? '144px' : 154.5 * (clientWidth / 578.88) + 'px';
  12. })
  13. };
  14. if (!doc.addEventListener) return;
  15. win.addEventListener(resizeEvt, recalc, false);
  16. doc.addEventListener('DOMContentLoaded', recalc, false);
  17. setTimeout(()=>recalc(),1000)
  18. })(document, window);
  19. };