改变元视口标签

问题描述 投票:0回答:1

我需要根据视觉视口的宽度更改元视口标签。我知道怎么做,但它不起作用。我认为这是因为该站点运行那部分 JS 的时间太晚,无法生效。可能不是这个,但这是我的第一个想法。

在我的 application.js 文件中:

$(document).ready(function() {

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

}

在我的 index.html 中:

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

关于如何让该块尽快运行以使其真正生效有什么想法吗?

jquery width meta-tags viewport
1个回答
0
投票

您可能遇到了设备的 dpi/清晰度问题,基本上 1 像素不等于 1 像素。这应该很容易研究。

© www.soinside.com 2019 - 2024. All rights reserved.