本文介绍了如何检测长触摸pressure与JavaScript的Andr​​oid和iPhone?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测长触摸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 };

这篇关于如何检测长触摸pressure与JavaScript的Andr​​oid和iPhone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 06:20