适配屏幕文字大小
直接上代码:
<script>
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))
console.log(devWidth, equipment)
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";
}
}
</script>