在Twitter Bootstrap中使用tap事件

Ana*_*man 6 jquery events touch jquery-mobile twitter-bootstrap

我正在使用twitter-bootstrap开发一个可以在多个设备上呈现的Web应用程序.

现在我想处理'tap'事件.所以我的问题是:

  1. 我可以使用jquery 1.7.2处理'tap'事件而不使用jqueryMobile吗?
  2. 如果上述问题的答案为否,那么如何将jqueryMobile与twitter-bootstrap集成.因为我尝试在我的twitter-bootstrap页面中包含jQueryMobile js,当我使用它时,页面中断!

mer*_*erv 5

抽头事件是一个jQuery移动事件,而不是具有规范的实际HTML5事件.HTML5指定了Android和iOS支持的触摸事件,而Twitter Bootstrap已经在其某些插件中使用了这些事件.

然而,事情的什么常识概念龙头事件可能是一个可以很容易地根据触摸事件的顺序触发它们.这是一个尝试:

// 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);
});
Run Code Online (Sandbox Code Playgroud)

这将触发一个水龙头如果事件touchend遵循touchstart内150毫秒(可以调节,当然).您可以尝试使用此代替包含jQuery mobile,如果您只是点击事件.


Ana*_*man 2

我最终找到了Touchable-jQuery-Plugin,它可以处理触摸及其相应的鼠标事件。