将touchmove事件从面板传播到jQueryMobile中的内容

时间:2014-01-15 17:31:15

标签: javascript jquery jquery-mobile

我在侧边小组myLink上有一个链接myPanel,有些内容myContent。我想:

  1. 触摸myLink上的myPanel,不要轻触
  2. myPanel关闭
  3. touchmove的事件监听器已添加到myContent(当前触摸尚未结束)
  4. myContent处理当前触摸,因为它刚刚开始侦听
  5. touchmove

    我这样做1到3:

    $( '#myLink' ).touchstart(function() {
      $( '#myPanel' ).panel( 'close' );
      // addEventListener for touchmove somewhere else 
    });
    

    我尝试在添加侦听器之前和之后触发touchstarttouchmovetouchend事件,并且没有。

    我在不同时间对touchmove内的myContent做出了不同的响应,所以我只想在触摸myLink之后添加此特定的听众。

    我不确定这是否重复,我一直在寻找,但我想我对术语不够熟悉。

1 个答案:

答案 0 :(得分:0)

我明白了。我没有在其他地方为touchmove添加侦听器,而是将touchmove绑定到myLink并直接调用外部调用的内容:

$( '#myLink' ).bind('touchstart',function() {
  $( '#myPanel' ).panel( 'close' );
  event.stopPropagation();
  // Don't addEventListener for touchmove
});
$( '#myLink' ).bind('touchmove',function(event) {
  event.stopPropagation();
  // directly call what my previous listener was calling:
  external.onTouchMove(event);
});

在处理外部事件时,诀窍是使用originalEvent

external.prototype.onTouchMove = function(e)
{
  var event = e.originalEvent;
  event.preventDefault();

  // Do what must be done
};