How to configure short and long press of a button?

Hello, I decided to try to implement the idea, the point is that with a short press on the button drops a menu and when you long hold and drops a popup window, a kind of 3D Touch, searching, found almost finished the code ,but I can't configure it so it worked, not so long ago started to learn JS, not whisking well. If anyone can help that would when you long press beginning to fall out popup window will be very grateful!
https://codepen.io/Swift_u/pen/zQQqmr
March 23rd 20 at 19:17
2 answers
March 23rd 20 at 19:19
I'm just learning, but I think you need to hang an EventListener on the "key events" that you need.
March 23rd 20 at 19:21
You can emulate a long press on the button. For example, like this:

var pressTimer;

$("a").mouseup(function(){
 // clean the timer
clearTimeout(pressTimer);
 return false;
}).mousedown(function(){
 // set the timer
 pressTimer = window.setTimeout(function() {
 // write here the code
},1000);
 return false; 
});


Continue to play with the timers. If too little time has passed, the recorded one-touch and given a menu. If a lot of open pop-up. Well, instead of a, of course, may be the mouse button, and the code of any button on the keyboard.
good code, but as I understand it, there is no reference to id so it will fire on any element on which you press - Brett_Toy58 commented on March 23rd 20 at 19:24

Find more questions by tags HTML