Skip to content

Instantly share code, notes, and snippets.

@padolsey
Created April 28, 2012 19:20
Show Gist options
  • Save padolsey/2521471 to your computer and use it in GitHub Desktop.
Save padolsey/2521471 to your computer and use it in GitHub Desktop.
Regular click event for touch devices [jQuery]
'createTouch' in document && (jQuery.event.special.click = {
setup: function(data, namespaces, eventHandle) {
var t;
$(this).bind('touchstart.touchClick', function() {
t = +new Date;
}).bind('touchend.touchClick', function(e) {
if (+new Date < t + 200) {
$(this).trigger('click', e);
}
})
},
teardown: function() {
$(this).unbind('.touchClick');
}
});
@padolsey
Copy link
Author

E.g. The iPad fakes Mouse events to increase compatibility. But they suck. And they're delayed.

This gives you back the click event, at least. So you can bind as you usually would:

$(el).bind('click', ...);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment