如何检测长触摸pressure与JavaScript的Andr​​oid和iPhone?JavaScript、pressure、Andr、iPhone

2023-09-04 05:36:11 作者:纯如小白花的少年^

如何检测长触摸pressure与JavaScript的Andr​​oid和iPhone? 本地JavaScript或jQuery的...

我想要的东西,听起来像:

 <输入类型=按钮onLongTouch =myFunc的();' />
 

解决方案

使用触摸结束检测长触摸,如果你希望事件的一段时间后,火就不会正常工作的问题。这是更好地使用触摸启动一个定时器,并清除触底事件定时器。下面的模式,可以用:

  VAR onlongtouch;
VAR定时器;
VAR touchduration = 500; //时间长短,我们希望用户去触摸我们做一些事情之前,

touchstart(){
    定时器= setTimeout的(onlongtouch,touchduration);
}

touchend(){

    //停止短的接触从触发事件
    如果(定时器)
        clearTimeout(定时器); // clearTimeout,不cleartimeout ..
}

onlongtouch =功能(){//做一些事情};
 

How to detect a long touch pressure with javascript for android and iphone? native javascript or jquery...

I want something that sound like :

<input type='button' onLongTouch='myFunc();' />

解决方案

The problem with using Touch End to detect the long touch is it won't work if you want the event to fire after a certain period of time. It is better to use a timer on touch start and clear the event timer on touch end. The following pattern can be used:

var onlongtouch; 
var timer;
var touchduration = 500; //length of time we want the user to touch before we do something

touchstart() {
    timer = setTimeout(onlongtouch, touchduration); 
}

touchend() {

    //stops short touches from firing the event
    if (timer)
        clearTimeout(timer); // clearTimeout, not cleartimeout..
}

onlongtouch = function() { //do something };