取消当前触摸事件,直到下一次触摸开始

Cancel current touch events until next touchstart

本文关键字:触摸 一次 开始 事件 取消      更新时间:2023-09-26

我必须使用javascript模拟长按。

var timer;
$(element).on('touchend',function(e){
 clearTimeout(timer);

});
 $(element).on('touchstart',function(e){
  timer=setTimeout(function()
    {
        //some action
    },1000);
    return true;
});
当触发显示上下文菜单

的操作时,如果抬起手指,则在触摸端事件中隐藏上下文菜单。我想避免这种情况。我想取消所有触摸事件,直到下一次触摸开始我该怎么办。问题仅在ios中。

嗯,你试过清除队列吗?也许使用.stop()来清除或.clearQueue()

参考: https://api.jquery.com/clearQueue/

参考: https://api.jquery.com/queue/

参考: https://api.jquery.com/stop/