1234567891011121314151617181920 |
- // 设置根节点html的字体大小用于移动端适配使用
- export const setHtmlFontSize = () => {
- console.count("setHtmlFontSize");
- (function (doc, win) {
- let resizeEvt = "orientationchange" in win ? "orientationchange" : "resize",
- recalc = function () {
- let htmlDom = doc.getElementsByTagName("html")[0];
- requestAnimationFrame(() => {
- let clientWidth = doc.documentElement.clientWidth || doc.body.clientWidth;
- if (!clientWidth) return;
- htmlDom.style.fontSize =
- clientWidth >= 578.88 ? "144px" : 154.5 * (clientWidth / 578.88) + "px";
- });
- };
- if (!doc.addEventListener) return;
- win.addEventListener(resizeEvt, recalc, false);
- doc.addEventListener("DOMContentLoaded", recalc, false);
- recalc();
- })(document, window);
- };
|