Safari iPad : prevent zoom on double-tap

前端 未结 8 1495
独厮守ぢ
独厮守ぢ 2020-12-05 12:09

I\'m creating a site on Safari for iPad. I need to prevent the zoom on double-tapping event but I have two problems:

  • a double tap doesn’t generate any events,
8条回答
  •  孤城傲影
    2020-12-05 12:42

    All solutions that I have seen (on this page and also elsewhere) have a side effect that they prevent in fast rate repeated clicks. Allows one click per 500ms or similar. This can be okay in some cases, but not eg. if you have a shooter or arrow buttons to allow fast moving from item to item.

    The easiest solution is this:

    $('#nozoom').on('touchstart', function(e)
    {
      fn_start(e);
      e.preventDefault();
    });
    

    This calls fn_start() (the actual callback function) every time when touch is started, but prevents then default zoomings etc.

    The working comparative example is here: http://jsbin.com/meluyevisi/1/. Green box prevents, red box allows.

提交回复
热议问题