简体   繁体   中英

Cancel current touch events until next touchstart

I have to simulate longpress using javascript.

var timer;

$(element).on('touchend',function(e){

 clearTimeout(timer);


});

 $(element).on('touchstart',function(e){

  timer=setTimeout(function()
    {
        //some action
    },1000);

    return true;

});

When the action is triggered which is displaying a context menu, after that if finger is lifted then at touchend event the context menu hides . I want to avoid this.I want cancel all touch events until next touchstart What should i do. The problem is only in ios.

Hmm, did you try clear queue ?? maybe use .stop() to clear or .clearQueue()

ref: https://api.jquery.com/clearQueue/

ref: https://api.jquery.com/queue/

ref: https://api.jquery.com/stop/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM