Altering meta viewport tag

别等时光非礼了梦想. 提交于 2019-12-08 05:44:07

问题


I need to alter the meta viewport tag dependent upon the width of the visual viewport. I know HOW to do it but it's not working, I think it's because the site is running that bit of JS too late for it to take effect. It may not be this but this is my first thought.

In my application.js file:

$(document).ready(function() {

  // If screen width is 480 or less then add meta viewport tag
  // (so default mobile display is used on iPads until that optimised view is added)
  if (window.innerWidth <= 480) { // This looks at the size of the visual viewport
    $('#viewport').attr('content', 'width=device-width');
  }

}

In my index.html:

<meta id="viewport" name='viewport'><!-- content attr is added via JS -->

Any ideas how I can get that block to run as early as possible so it actually takes effect?

Thanks Neil


回答1:


You may be running into an issue with the dpi/definition of the device, basically 1 pixel is not equal to 1 pixel. This should be fairly easy to research.



来源:https://stackoverflow.com/questions/11075090/altering-meta-viewport-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!