手机端自适应屏幕


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

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();};

2、要在head标签 内部加viewport 代码如下 ↓

wap