在Android上确定长按(长preSS,轻触Hold)与jQuery轻触、preSS、Android、Hold

2023-09-07 08:38:16 作者:爺、嗨爆全场

我已经能够successfully玩与touchstart,touchmove,并使用jQuery在Android touchend事件和一个HTML页面。现在,我想看到​​的伎俩就是确定一个长按事件,其中一个水龙头,并持有3秒。我似乎无法想出解决办法呢。我想这纯粹是没有的jQuery煎茶触摸,JQTouch,jQMobile等。

I've been able to successfully play with the touchstart, touchmove, and touchend events on Android using jQuery and an HTML page. Now I'm trying to see what the trick is to determine a long tap event, where one taps and holds for 3 seconds. I can't seem to figure this out yet. I'm wanting to this purely in jQuery without Sencha Touch, JQTouch, jQMobile, etc.

我喜欢jQTouch的概念,虽然它不给我一大堆我的一些与之code休息。随着煎茶触摸,我不是背离的jQuery到Ext.js的粉丝,做的Javascript抽象一些新的方法,尤其是在jQuery是很能干。所以,我想独自摸不着头脑与jQuery。我已经能够做很多jQTouch和煎茶触摸的东西我自己的使用jQuery的。而jQMobile仍然过于测试阶段,没有足够定向到Android呢。的

推荐答案

定时器不使用,但用户后只火释放他的手指很长的自来水后。

Timers not used but will only fire after user releases his finger after a long tap.

var startTime, endTime;
var gbMove = false;

window.addEventListener('touchstart',function(event) {
    startTime = new Date().getTime(); 
    gbMove = false;        
},false);

window.addEventListener('touchmove',function(event) {
  gbMove = true;
},false);

window.addEventListener('touchend',function(event) {
    endTime = new Date().getTime();
    if(!gbMove && (endTime-startTime)/1000 > 2)
        alert('tap hold event');      
},false);