自适应是每个开发者必走的路,该篇掘文是前者踩过一些坑 而踏出来的几条路,希望这些经验能在开发的过程中帮助到大家!!!
1.传统布局 => rem
//方式一
const deviceWidth = document.documentElement.clientWidth || document.body.clientWidth;
document.querySelector('html').style.fontSize = deviceWidth / 7.5 + 'px';
//方式二
document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + "px";
window.addEventListener(
"resize",
function(){
document.documentElement.style.fontSize =
document.documentElement.clientWidth / 7.5 + "px";
},
false
);
//方式一和方式二 效果一样
复制代码
2.只希望看到一种单位,那就是 => px
方案一:lib-flexible+postcss-pxtorem
不足:
1.两个插件需要配套使用,