1

I'm trying to make a javascript script that captures the ordinary click, double click, and click and keep clicked for 2 seconds, but did not succeed. The click and double click ok, but how can I do the three in the same function, something like:

var click = function(element,click,dblclick,keedClicked){
   //function return callback for click, dblclick and keepClicked
}

click('element',function(){
   //code for click
},function(){
   //code for double click
},function(){
   //code for keep click
});

My problem is to join these functions in a function. Ex .: If I click on a button, it is an action. If I double-click, it makes other action. If I click and hold, it makes a third action. But before the action, we need to detect the type of click.

Another example is: In a button, if I click, I open the options, if I double-click, I edit the name of the label, and opens up the Advanced Options button (or something). A button, three possibilities of action.

  • Why don't you use jquery ? https://api.jquery.com/dblclick/ Then you can use http://stackoverflow.com/a/7845282/797495 – Pedro Lobito Oct 11 '15 at 03:01
  • There is no such default event as "click and keep clicked for 2 secondos". You would have to create such an event. – Rahly Oct 11 '15 at 03:03
  • What do you mean by keepClicked? The mousedown event? Holding in the click button over an element? – pyius Oct 11 '15 at 03:05
  • 90% of the features of jQuery I will not use, I'll use pure javascript to not need to carry all the jquery each time you load the page –  Oct 11 '15 at 03:06
  • @pyius: - Yes. I need something like 3D Touch of iOS 9 –  Oct 11 '15 at 03:07
  • @Rahly - Yes, I'm trying to create a function to do this in javascript –  Oct 11 '15 at 03:09
  • @James For the "click and hold for two seconds", you could use `mousedown` and `mouseup`. In `mousedown`, set a `startTime` variable to the current time, and in `mouseup`, check if `new Date() - startTime > 1000 * 2`. If so, the user clicked and held down for more than two seconds before letting go. – rgajrawala Oct 11 '15 at 03:15
  • @PedroLobito - How is that even close to a valid response? Recommending an entire library for a simple Javascript question does not seem helpful – Jesse Oct 11 '15 at 03:30
  • @Jesse As far as I remember, I only posted a comment. If you have an answer go ahead. – Pedro Lobito Oct 11 '15 at 03:47

0 Answers0