移动端样式兼容rem配置
fnResize();
window.onresize = function () {
fnResize();
window.addEventListener("resize", fnResize);
};
function fnResize() {
let devWidth = document.documentElement.clientWidth || window.innerWidth;
let equipment = (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))
if (equipment) {
if (devWidth >= 750) {
devWidth = 750;
}
if (devWidth <= 320) {
devWidth = 320;
}
document.documentElement.style.fontSize = parseInt(devWidth / 23) + "px";
}else{
document.documentElement.style.fontSize = 16 + "px";
}
}
使用方法,直接在需要使用的页面引入该文件