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.
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 > |
2 |
$( '#button' ).on( 'taphold' , function () { |
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.
2 |
$( '#button' ).on( 'taphold' , function () { |
5 |
.on( 'click' , function () { |
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 () { |
5. Overide the default delay between hold and click events. Default: 500ms (0.5s).
1 |
$( '#element' ).on( 'taphold' , { |
6. Prevent the default context menu event on mobile devices. Default: false.
1 |
$( '#element' ).on( 'taphold' , { |
Changelog:
2019-12-23
- fixed click-preventing
- enhanced log
2019-12-22
2019-12-21
2019-12-18
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.