Using tap events with Twitter Bootstrap

I use twitter-bootstrap to develop a web application that can display on multiple devices.

Now I would like to handle the 'tap' event. So my question is:

  • Is it possible to handle the tap event using jquery 1.7.2 without using jqueryMobile?
  • If the answer to the above question is no, then how do I integrate jqueryMobile with twitter bootstrap. The reason I tried to include jQueryMobile js in my twitter-bootstrap page, and when I use it, the page breaks!
+6
source share
2 answers

Finally I ended up with Touchable-jQuery-Plugin , which handles touch and corresponding mouse events.

+2
source

The tap event is a jQuery Mobile event and is not an actual HTML5 event with a specification. HTML5 indicates touch events that are supported on Android and iOS, and Twitter Bootstrap already uses these events in some of its plugins.

However, based on common sense that there might be a tap event, you can easily trigger them based on a sequence of sensory events. Here is an attempt:

// 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 cause the event to touch if touchhend should touchstart within 150ms (which you can configure, of course). You can try using this instead of turning on jQuery mobile, if the click event is all you need.

+5
source

Source: https://habr.com/ru/post/924273/


All Articles