12345678910111213141516171819 |
- // 设置根节点html的字体大小用于移动端适配使用
- export const setHtmlFontSize = () => {
- console.count("setHtmlFontSize");
- (function (doc, win) {
- var htmlDom = doc.getElementsByTagName("html")[0],
- resizeEvt = "orientationchange" in win ? "orientationchange" : "resize",
- recalc = function () {
- requestAnimationFrame(() => {
- var 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);
- setTimeout(()=>recalc(),1000)
- })(document, window);
- };
|