我在侧边小组myLink
上有一个链接myPanel
,有些内容myContent
。我想:
myLink
上的myPanel
,不要轻触myPanel
关闭touchmove
的事件监听器已添加到myContent
(当前触摸尚未结束)myContent
处理当前触摸,因为它刚刚开始侦听touchmove
醇>
我这样做1到3:
$( '#myLink' ).touchstart(function() {
$( '#myPanel' ).panel( 'close' );
// addEventListener for touchmove somewhere else
});
我尝试在添加侦听器之前和之后触发touchstart
,touchmove
和touchend
事件,并且没有。
我在不同时间对touchmove
内的myContent
做出了不同的响应,所以我只想在触摸myLink
之后添加此特定的听众。
我不确定这是否重复,我一直在寻找,但我想我对术语不够熟悉。
答案 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
};