JS控制适配屏幕

适配原理:将px换成rem,动态改变根元素html的font-size.

  • //得到手机屏幕的宽度
  • let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
  • //得到html的Dom元素
  • let htmlDom = document.getElementsByTagName('html')[0];
  • //设置根元素字体大小
  • htmlDom.style.fontSize= htmlWidth/20 + 'px';

posted @ 2018-12-13 18:35  山里娃的技术之家  阅读(968)  评论(0编辑  收藏  举报