tap hold event handler - Free Download Click/Tap And Hold Event Handler - jQuery Taphold

Free Download Click/Tap And Hold Event Handler – jQuery Taphold

Posted on

This time I will share jQuery Plugin and tutorial about Click/Tap And Hold Event Handler – jQuery Taphold, hope it will help you in programming stack.

tap hold event handler - Free Download Click/Tap And Hold Event Handler - jQuery Taphold
File Size: 4.46 KB
Views Total: 1133
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

The Taphold library provides a tap and hold event listener which will be fired when an element is clicked/tapped/pressed and held for 0.5s.

How to use it:

1. Download and load the taphold.js script after jQuery.

1 <script src="/path/to/cdn/jquery.slim.min.js"></script>
2 <script src="/path/to/taphold.js"></script>

2. Attach the tap and hold event handlers to the targer element and done.

1 <div id="button"></div>
1 $(function(){
2   $('#button').on('taphold', function () {
3     // do something here
4   });
5 });

3. Combine the tap and hold event with click event. It is useful to trigger a normal click event when the button is released before the delay.

1 $(function(){
2   $('#button').on('taphold', function () {
3     // do something here
4   })
5   .on('click', function () {
6     // do something here
7   });
8 });

4. The plugin also supports jQuery event delegation which allows you to attach the click and tap event to a parent element, that will fire for all descendants matching a selector, whether those descendants exist now or are added in the future.

1 $('#button').on('taphold', 'p', function () {
2   // do something here
3 });

5. Overide the default delay between hold and click events. Default: 500ms (0.5s).

1 $('#element').on('taphold', {
2   delay: 2000
3 },function () {
4   // do something here
5 });

6. Prevent the default context menu event on mobile devices. Default: false.

1 $('#element').on('taphold', {
2   prevent<a href="https://www.jqueryscript.net/menu/">Menu</a>: true
3 },function () {
4   // do something here
5 });

Changelog:

2019-12-23

  • fixed click-preventing
  • enhanced log

2019-12-22

  • fix click-preventing

2019-12-21

2019-12-18

  • fix click-preventing

2019-12-17

  • prevent click after taphold in some cases

This awesome jQuery plugin is developed by IITC-CE. For more Advanced Usages, please check the demo page or visit the official website.

source : jquery.net