Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Touch device ghost click triggers on different element Reply To: Touch device ghost click triggers on different element

#252939
Shikkediel
Participant

For now I can’t see straight anymore…

Still enough to not stop, I suppose. :-/

But this one’s rather nice…

$('div').on('touchstart click', {flag: false}, function(e) {

if (e.type == 'click' && e.data.flag) return;
  e.data.flag = e.type == 'touchstart';

//do stuff on either event
});

codepen.io/anon/pen/wJpYBO

Even though it doesn’t reset, which would be convenient with devices that support both.

Now I’m calling it a day…

codepen.io/anon/pen/evyPvB

$('div').on('touchstart touchcancel click', {flag: false}, function(e) {

  if (e.type == 'touchcancel' || e.type == 'click' && e.data.flag) {
    e.data.flag = false;
    return;
  }

  e.data.flag = e.type == 'touchstart';

  //do stuff on either event
});