I am using twitter-bootstrap to develop a web application that can render on multiple devices.
Now I would like to handle the 'tap' event. So my question here is:
The tap event is a jQuery Mobile event and is not an actual HTML5 event which has a specification. HTML5 specifies touch events, which are supported on Android and iOS, and Twitter Bootstrap already utilizes those event in some of its plugins.
However, going on a common sense notion of what a tap event might be, one could easily trigger them based on a sequence of touch events. Here's a try:
// listen for a touchstart event
$('body').on('touchstart.tap',function (e) {
// listen for a touchend event
$(e.target).one('touchend.tap',function() {
$(e.target).trigger('tap');
});
// cancel it in 150ms
setTimeout(function () {
$(e.target).off('touchend.tap');
},150);
});
This will trigger a tap event if a touchend follows a touchstart within 150ms (which you can adjust, of course). You could try using this in lieu of including jQuery mobile if a tap event is all you're after.
I finally hit up on Touchable-jQuery-Plugin which handles touch and their corresponding mouse events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With