如何使用Android和iPhone的javascript检测长按压力?

如何使用Android和iPhone的javascript检测长按压力?,第1张

如何使用Android和iPhone的javascript检测长按压力?

使用“触摸结束”检测长时间触摸的问题是,如果您希望事件在一定时间后触发,则它将无法正常工作。最好在触摸开始时使用计时器,并在触摸结束时清除事件计时器。可以使用以下模式:

var onlongtouch; var timer;var touchduration = 500; //length of time we want the user to touch before we do somethingtouchstart() {    timer = setTimeout(onlongtouch, touchduration); }touchend() {    //stops short touches from firing the event    if (timer)        clearTimeout(timer); // clearTimeout, not cleartimeout..}onlongtouch = function() { //do something };


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5641179.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存