Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Mobile - change the taphold sensitivity

Tags:

jquery

mobile

I have a problem with the JQuery mobile app I am developing on my Android.

Often when I mean to just scroll a list of items, the taphold even on the item I am touching is triggered.

That's very frustrating for my users.

What can I do about it?

Can I change the sensitivity of the taphold event?

Unfortunately I can't find anything on Google.

Thanks,
Dan

like image 539
Dan Avatar asked Feb 22 '23 11:02

Dan


1 Answers

In jQuery-mobile 1.1.*, they have added more convenient ways to configure touch events: http://jquerymobile.com/demos/1.1.1/docs/api/events.html

For taphold, you can change the amount of time a tap should last before triggering the event by assigning a value to $.event.special.tap.tapholdThreshold.

This value should be set in the mobileinit event, before importing JQM, but after importing jQuery. For instance, I did the following to avoid any overlap between the swipe and taphold events:

<script type="text/javascript" src="/Scripts/jquery.min.js"></script>
<!-- JQM default options must be set after jQuery and before jQuery-mobile -->
<script type="text/javascript">
    $(document).bind("mobileinit", function () {
        $.event.special.tap.tapholdThreshold = 1000,
        $.event.special.swipe.durationThreshold = 999;
    });
</script>
<script type="text/javascript" src="/Scripts/jquery.mobile-1.1.0.js"></script>
like image 126
Alejo Avatar answered Feb 26 '23 20:02

Alejo