移动端适配

51 阅读1分钟

第一种方案: `(function(){ const PAGE_WIDTH = 750; // 设计稿的宽度 const PAGE_FONT_SIZE = 100;// 设计稿1rem的大小

  const setView = () => {
      //设置html标签的fontSize
      document.documentElement.style.fontSize = PAGE_FONT_SIZE * (document.documentElement.clientWidth) / PAGE_WIDTH + 'px';
      console.log('111',document.documentElement.clientWidth);
    }
    window.onresize = setView() // 如果窗口大小发生改变,就触发 setView 事件
}())`