I want to be able to fire an event when a user clicks on a button, then holds that click down for 1000 to 1500 ms.
Is there jQuery core functionality or a plugin that already enables this?
Should I roll my own? Where should I start?
I want to be able to fire an event when a user clicks on a button, then holds that click down for 1000 to 1500 ms.
Is there jQuery core functionality or a plugin that already enables this?
Should I roll my own? Where should I start?
Presumably you could kick off a
setTimeout
call inmousedown
, and then cancel it inmouseup
(ifmouseup
happens before your timeout completes).However, looks like there is a plugin: longclick.
I made a simple JQuery plugin for this if anyone is interested.
http://plugins.jquery.com/pressAndHold/
Here's my current implementation:
Aircoded (but tested on this fiddle)
I wrote some code to make it easy
See on JSFiddle
Now you need just to set the time of holding and add
clickHold
event on your elementTry this: