I am building a web application using jQuery Mobile for use on a desktop, iPad and Android phone. I want the user to be able to click a button to increase (or decrease) the value. My code works fine on the desktop, but on iPad and Android, when the user quickly clicks, the screen zooms in instead of increasing the value. I am trying to implement the solution here: Safari iPad: prevent double-tap enlargement (and, in particular, the refinement provided by Christopher Thomas.
Here is my code for the button and value:
<div class="content">
<div id ="status_page" data-role="page">
<div data-role="content" data-theme="d">
<div id="val">1</div>
<div id="but" data-role="button">Click</div>
</div>
</div>
</div>
Here is my event handler for clicking on the button (by the way, I think the parameters in Christopher's answer were wrong):
$(".content") .on("click",$("#but"),function(){
var but_val = parseInt($("#val").text());
$("#val").text(but_val+1);
});
... and here is the nodoubletap function:
(function($) {
$.fn.nodoubletapzoom = function() {
if($("html.touch").length == 0) return;
$(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;
}
e.preventDefault();
$(this).trigger('click');
});
};
})(jQuery);
. ( ). $(this).trigger('click'); $('#but').trigger('click');, , . , , , touchstart. - , .