浏览代码

优化动画频率

username 1 年之前
父节点
当前提交
6376545b8f
共有 1 个文件被更改,包括 5 次插入3 次删除
  1. 5 3
      src/utils/index.ts

+ 5 - 3
src/utils/index.ts

@@ -4,9 +4,11 @@ export const setHtmlFontSize = () => {
         var htmlDom = doc.getElementsByTagName('html')[0],
             resizeEvt = 'orientationchange' in win ? 'orientationchange' : 'resize',
             recalc = function () {
-                var clientWidth = doc.documentElement.clientWidth || doc.body.clientWidth;
-                if (!clientWidth) return;
-                htmlDom.style.fontSize = clientWidth>=579 ? '144px' : 145 * (clientWidth / 579) + 'px';
+                requestAnimationFrame(()=>{
+                    var clientWidth = doc.documentElement.clientWidth || doc.body.clientWidth;
+                    if (!clientWidth) return;
+                    htmlDom.style.fontSize = clientWidth>=579 ? '144px' : 145 * (clientWidth / 579) + 'px';
+                })
             };
         if (!doc.addEventListener) return;
         win.addEventListener(resizeEvt, recalc, false);