设置rem
(function() {
// 以下是定义rem的基本单位的代码
var remSwitch = true;
var oW = null;
var timer = null;
// 初始化
reset();
// 监听页面变化
window.addEventListener("orientationchange", function() {
reset();
});
window.addEventListener("resize", function() {
reset();
});
// 计算得出rem基本大小
function reset() {
if (remSwitch) {
remSwitch = false;
oW = document.documentElement.clientWidth;
if (oW > 1920) {
oW = 1920;
}
if (1500 > oW && oW >= 1366) {
oW = document.documentElement.clientWidth*1.1;
}
if (1366 > oW && oW >= 1200) {
oW = document.documentElement.clientWidth*1.2;
}
if (1200 > oW && oW >= 991) {
oW = document.documentElement.clientWidth*1.3;
}
if (991 >= oW && oW >= 768) {
oW = document.documentElement.clientWidth*1.4;
}
if (768 >= oW) {
oW = 1100;
}
document.querySelector("html").style.fontSize = oW / 19.2 + "px";
timer = setTimeout(function() {
remSwitch = true;
clearTimeout(timer);
}, 200);
}
}
})();