有什么通用的放法吗?这样写好麻烦
我是这样减少获取dom的获取:
const bodyDom = document.body;
const htmlDom = document.documentElement;
const htmlWidth = bodyDom.clientWidth || htmlDom.clientWidth;
htmlDom.style.fontSize = htmlWidth / 10 + 'px';
window.addEventListener('resize', (e) => {
const htmlWidth = bodyDom.clientWidth || htmlDom.clientWidth;
htmlDom.style.fontSize = htmlWidth / 10 + 'px';
})获取窗口宽度那段代码是通用的,其他的,多敲点代码就好了