1.首先引入meta视口标签,快捷键:meta:vp
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
<link rel="stylesheet" href="css/bootstrap.css"/>
2.js代码
$(function(){
function setRem(){
var clientWidth=$(window).width();
var nowRem=(100*clientWidth/375);/*375这个值是设计图中测量值的一半*/
$("html").css("font-size",parseInt(nowRem, 10)+"px");
};
setRem();
$(function(){
var timer;
$(window).bind("resize",function(){
clearTimeout(timer)
timer=setTimeout(function(){
setRem();
}, 100)
})
});
});