Button press and hold for action in Android PhoneG

2019-04-16 15:39发布

I'm need to preform a specific action in my app if the user presses and holds a button for a few second, if the user removes his finger from the button before the delay runs out, then this action will be cancelled. I use 'ontouchstart' event for the press.

Is there any way i can achieve this using html and javascript?

Thanks.

2条回答
男人必须洒脱
2楼-- · 2019-04-16 16:10

Here is a code snippets to achieve this particular requirement,

var pressTimer;
$("#btnClick").mouseup(function(){
  clearTimeout(pressTimer);
  return false;
});
$("#btnClick").mousedown(function(){
  pressTimer = window.setTimeout(function() { ... your code here ...},time_delay)
  return false; 
}); 
查看更多
地球回转人心会变
3楼-- · 2019-04-16 16:34

Search for keyup and keydown events in javascript

useful link: http://www.webmonkey.com/2010/02/javascript_events/#keydown

查看更多
登录 后发表回答