jquery mobile - JQM: taphold event does not prevent click event -


i'm trying bind taphold event on link under jqm.

problem, occurs is, if user, doing long click, releases mouse on link - click event fired. of course not intended - want separate these events.

so have link this:

<a href="do-smth">link</a> 

and else, should done on long tap

$("a").on("taphold", function(event) {do_smth_else()}); 

and both do-smth , do_smth_else executed, when user makes long tap , releases mouse on link.

here http://jsfiddle.net/gardenofemuna/68r4gph6/1/ example.

does have remedy against it?

as far can tell, there no other way preventing default behavior of vclick event:

$(".link").on({     taphold: function() {         post('long tap fired');     },     vclick: function(e) {         e.preventdefault();     } }); 

this way, taphold handlers invoked default action associated link canceled.

you find updated fiddle here.

if want default behavior of link still occur, if long tap not performed, have associate state element itself. jquery's data() facility allows write:

$(".link").on({     taphold: function() {         post('long tap fired');         $(this).data("longtapregistered", true);     },     "vclick vmouseout": function(e) {         var $this = $(this);         if (e.type == "vclick" && $this.data("longtapregistered")) {             e.preventdefault();         }         $this.removedata("longtapregistered");     } }); 

note have remove our persisted state on vmouseout avoid issue described in comment.

you find fiddle demonstrating here.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -