Safari iPad : prevent zoom on double-tap

前端 未结 8 1458
独厮守ぢ
独厮守ぢ 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:43

    try this modified code. It should work for both android and IOS devices

    (function($) {
    $.fn.nodoubletapzoom = function() {
        $(this).bind('touchstart', function preventZoom(e){
            var t2 = e.timeStamp;
            var t1 = $(this).data('lastTouch') || t2;
            var dt = t2 - t1;
            var fingers = e.originalEvent.touches.length;
            $(this).data('lastTouch', t2);
            if (!dt || dt > 500 || fingers > 1){
                return; // not double-tap
            }
            e.preventDefault(); // double tap - prevent the zoom
            // also synthesize click events we just swallowed up
            $(e.target).trigger('click');
        });
    };
    })(jQuery);
    

    Then apply the nodoubletapzoom() to the body tag

    $("body").nodoubletapzoom();
    
    0 讨论(0)
  • 2020-12-05 12:45

    Mobile Safari does not support the javascript ondblclick event. It's interpreted by Safari as a "zoom".

    Raul Sanchez has posted a potential solution: http://appcropolis.com/implementing-doubletap-on-iphones-and-ipads/

    0 讨论(0)
提交回复
热议问题