Home › Forums › JavaScript › Touch device ghost click triggers on different element › Reply To: Touch device ghost click triggers on different element
March 19, 2017 at 5:56 am
#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
});
Even though it doesn’t reset, which would be convenient with devices that support both.
Now I’m calling it a day…
$('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
});