繁体   English   中英

从dom中删除任何元素后,Touchmove事件将停止触发

[英]Touchmove event stops triggering after any element is removed from dom

在触摸设备上,如iPad(或铬合金的移动仿真模式 )。 当跟踪touchmove上的touchmove事件并从dom touchmove事件中删除一个元素(在touchstart上启动)时,从身体停止触发。

我做了一个例子http//jsbin.com/yinodosuxo/1/edit?js,console,output

即使删除了子元素, touchmove还有什么方法可以继续工作吗?

我通过缓存元素来修复此问题,直到发出touchend事件。 触发touchstart事件的视图的伪代码如下所示:

view.remove = function () {
  if (didViewStartTouchEvents) {
    var _this = this;
    this.hideElement(); // display: none, opacity: 0, etc
    elementCache.appendChild(this); //append this element to some other place like body. Not needed but might be handy depending on situation
    document.body.addEventListener('touchend', function () {
      _this.didViewStartTouchEvents = false;
      _this.remove();
    });
  } else {
    // regular remove & cleanup
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM