简体   繁体   中英

300ms Delay Between Taps iOS WebApp

I'm writing a game, so it requires I tap more then a few times every 300ms. I already have fastclick.js and it works, however I cannot tap more then once in a 300ms period.

For example I'll tap once, and it immediately reacts, but if I tap again before the 300ms is up, the event is not fired.

Fast Click:

//remove 300ms delay on mobile
  FastClick.attach(document.body);

My event:

//when the game is clicked
  window.onclick = function(e){
    if(e.x > window.innerWidth/2){
      move('right');
    } else {
      move('left');
    }
  }

I discovered it was an issue with using fastclick.js for this purpose. fastclick.js fires the onclick event, but has to wait for the regular onclick event to be fired in order to stop it.

$('.punch')[0].ontouchend = function() {
  $('.console').append((Date.now() - time) + ' Tap<br>');
  tap = true;
}

Then I added a click event.

$('.punch')[0].onclick = function() {
  if (!tap) {
    $('.console').append((Date.now() - time) + ' Click<br>');
    time = Date.now();
  }
}

JSFiddle: https://jsfiddle.net/jersh/L6z1d2ev/6/

Fastclick.js is prime for none repetitive taps, and will still let you use gestures. This doesn't.

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