JS 控制VIEWPORT在微信上正常显示

  • A+
所属分类:其他
源代码   
  1. <meta name='viewport' content='width=device-width, target-densityDpi=device-dpi, user-scalable=yes'>
  2. var viewport = document.querySelector('meta[name=viewport]');
  3.  var winWidths=$(window).width();
  4.  var densityDpi=640/winWidths;
  5.  densityDpi= densityDpi>1?300*640*densityDpi/640:densityDpi;
  6.  if(isWeixin()){
  7.  viewport.setAttribute('content', 'width=640, target-densityDpi='+densityDpi);
  8.  }else{
  9.  viewport.setAttribute('content', 'width=640, user-scalable=no');
  10.  window.setTimeout(function(){
  11.  viewport.setAttribute('content', 'width=640, user-scalable=yes');
  12.  },1000);
  13.  }
  14.  function isWeixin(){
  15.  var ua = navigator.userAgent.toLowerCase();
  16.  if(ua.match(/MicroMessenger/i)=='micromessenger') {
  17.  return true;
  18.  } else {
  19.  return false;
  20.  }
  21.  }
  • 我的微信小程序
  • 长按二维码识别查看微信小程序
  • weinxin
  • 我的个人微信号
  • 长按识别加我个人微信号
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: