手机端自适应屏幕

一、经过这段js来替代媒体查询(页面具体宽常见:720/750)单位用rem,经过js所得比例为100:1 此时假定html{font-size:100px} 即1rem = 100px 具体代码以下 ↓html

function pgScale(){
    var deviceWidth = document.documentElement.clientWidth;
    if(deviceWidth > 720) deviceWidth = 720;
    document.documentElement.style.fontSize = deviceWidth / 7.2 + 'px';
}
pgScale();
window.onresize=function(){pgScale();};

二、要在head标签 内部加viewport 代码以下 ↓
<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" name="viewport" id="viewport">ide

相关文章
相关标签/搜索