如何使用 JavaScript 设置移动 Safari 的缩放级别?

发布于 2024-10-08 12:53:39 字数 41 浏览 0 评论 0原文

如何使用 JavaScript 设置移动 Safari 的缩放级别?

How can I use JavaScript to set the zoom level on mobile safari?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

九八野马 2024-10-15 12:53:39

[更新] 您似乎想在移动 Safari 中捕获双击。您可以通过处理 touchend 事件来做到这一点,或者使用可用的框架,例如 此网站

看看修改后的演示:http://jsbin.com/atayo4/20

  <p id="tap">double tap to zoom</p>
  <input id="zoomWidth" type="text" value="400" />
  <p id="feedback"></p>

$(document).ready(function(){
  $('#tap').doubletap(
    // double tap handler
    function(e) {
      $('#feedback').addClass('red').html('double tap! Zoom width: ' + $('#zoomWidth').val());

      var zoomWidth = $('#zoomWidth').val();

      // zoom with the new width
      $('meta[name="viewport"]').attr('content', 'width=' + zoomWidth + ', user-scalable:no');

      $('#zoomWidth').val(parseInt(zoomWidth, 10) - 25);
    },

    // single tap handler
    function(e) {
      $('#feedback').removeClass('red').html('single tap! Zoom width: ' + $('#zoomWidth').val());
    },

    // double tap delay, default 500
    400
    );
});

[UPDATED] It seems that you want to capture double taps in mobile Safari. You could do that by handling the touchend event, or use an available framework, such as provided in this site.

Take a look at the revised demo: http://jsbin.com/atayo4/20

  <p id="tap">double tap to zoom</p>
  <input id="zoomWidth" type="text" value="400" />
  <p id="feedback"></p>

$(document).ready(function(){
  $('#tap').doubletap(
    // double tap handler
    function(e) {
      $('#feedback').addClass('red').html('double tap! Zoom width: ' + $('#zoomWidth').val());

      var zoomWidth = $('#zoomWidth').val();

      // zoom with the new width
      $('meta[name="viewport"]').attr('content', 'width=' + zoomWidth + ', user-scalable:no');

      $('#zoomWidth').val(parseInt(zoomWidth, 10) - 25);
    },

    // single tap handler
    function(e) {
      $('#feedback').removeClass('red').html('single tap! Zoom width: ' + $('#zoomWidth').val());
    },

    // double tap delay, default 500
    400
    );
});
埋葬我深情 2024-10-15 12:53:39

据我所知,您可以通过更改 body 元素的样式“-webkit-text-size-adjust”来更改文本大小的缩放系数。

检查此链接以获取更多信息:

http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html%23//apple_ref /doc/uid/TP30001266--webkit-text-size-调整

As far as I know, you can change the zoom factor the text size by changing the style '-webkit-text-size-adjust' of body element.

Check this link for more information:

http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html%23//apple_ref/doc/uid/TP30001266--webkit-text-size-adjust

柳若烟 2024-10-15 12:53:39

我尝试使用 JavaScript 操作元标记中的最小/最大比例和宽度,但没有成功。我不会尝试使用代码设置缩放级别(我认为这是不可能的),而是将在相对较大的图像之上创建小的隐形框。这将允许用户通过本机双击图像的有趣部分来放大(和缩小)。

I tried manipulating the min/max scales and width in the meta tag with JavaScript to no avail. Instead of trying to set the zoom level with code (I'm thinking it's not possible), I'm going to create small invisible boxes on top of my relatively large image. This will allow users to zoom in (and out) via native double-tap on interesting sections of the image.

云胡 2024-10-15 12:53:39

试试这个:

<meta name="viewport" content="width=device-width; initial-scale=1.0; user-scalable:no;">

来源

Try this:

<meta name="viewport" content="width=device-width; initial-scale=1.0; user-scalable:no;">

Source

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文