物理像素自适应布局

分享一个我常用的页面物理像素自适应布局方法:

window.onload = function (){
    let dpr = window.devicePixelRatio;
    let scale = 1/dpr;
    let width = document.documentElement.clientWidth;
    let metaNode = document.querySelector('meta[name="viewport"]');
    metaNode .setAttribute('content','width=device-width,inital- 
    scale='+scale+',user-scalable');
    let htmlNode = document.querySelector('html');
    htmlNode.style.fontSize = width * dpr + 'px';
   
}

 

window.onload = function (){

  let = width = document.documentElement.clientWidth;
  let  htmlNode = document.querySelector('html') ;
  htmlNode.style.fontSize = width + 'px';
}

 

posted @ 2020-10-14 20:42  cruor  阅读(148)  评论(1编辑  收藏  举报