h5页面自适应手机屏幕宽度

在html head中添加:

<script type="text/javascript">
  var phoneScale = parseInt(window.screen.width)/640;
  document.write('<meta name="viewport" content="width=640, minimum-scale = '+ phoneScale +', maximum-scale = '+ phoneScale +',   target-densitydpi=device-dpi">');
</script>

 

在css中给body添加属性:

  width: 640px;

posted @ 2016-05-12 09:56  月下小狸123  阅读(3094)  评论(0编辑  收藏  举报