smart-admin/rc-busness/config/rem.js
2022-01-06 03:25:11 +00:00

20 lines
870 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 隔离作用域,避免全局变量的污染
!(function(){
function setHtmlFontSize(){
// 1.获取手机屏幕宽度
var w = document.documentElement.getBoundingClientRect().width; //如果用window.innerwidth的话改变窗口大小不能够及时获取窗口大小
// console.log(w);
// 2.根据屏幕宽度计算html font-size大小, 7.5指的是设计稿的宽度为750如果在公司中设计稿的尺寸为720那么应该除以7.2
var f = w/40;
// 3.设置html 的font-szie
document.documentElement.style.fontSize=f+"px";
}
setHtmlFontSize();
window.addEventListener("resize",function(){
// setTimeout 是为了解决在苹果手机上的闪屏情况
setTimeout(function(){
setHtmlFontSize();
},300)
})
})();