level 1
!(function (win, doc) {
function setFontSize() {
const winWidth = window.innerWidth;
doc.documentElement.style.fontSize = (winWidth / 750) * 100 + 'px';
}
const evt = 'onorientationchange' in win ? 'orientationchange' : 'resize';
let timer = null;
win.addEventListener(evt, function () {
clearTimeout(timer);
timer = setTimeout(setFontSize, 300);
}, false);
win.addEventListener("pageshow", function (e) {
if (e.persisted) {
clearTimeout(timer);
timer = setTimeout(setFontSize, 300);
}
}, false);
//初始化
setFontSize();
}(window, document));
2023年08月02日 03点08分
3
用rem 100px = 1rem
2023年08月02日 03点08分
把这代码放上去就可以适配了
2023年08月02日 03点08分
缺点是ipd这种适配的不行。纯手机端凑合
2023年08月02日 04点08分
level 11
都行吧,看设计稿咯。px转vw,vh或者转rem都行啊
2023年08月02日 05点08分
10
level 6
我一般是用那个flexible.js的插件,大致的作用就是依据你屏幕的宽高比来动态修改body的font-size属性,然后再结合rem使用,就能解决大部分的适配问题
2023年08月02日 07点08分
16