从dom中删除任何元素后,Touchmove事件将停止触发 [英] Touchmove event stops triggering after any element is removed from dom

查看:201
本文介绍了从dom中删除任何元素后,Touchmove事件将停止触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPad等触控设备上(或镀铬中的移动仿真模式)。在主体上跟踪 touchmove 事件并从dom touchmove 中删除​​一个元素(在touchstart上启动)从身体停止触发的事件。

On touch devices such as iPad (or mobile emulaton mode in chrome). When tracking touchmove event on body and removing an element (on which touchstart started) from dom touchmove events from body stops triggering.

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

有没有 touchmove 的方法是否在删除子元素后继续工作?

Is there any way for the touchmove continue working even after the child element is removed?

推荐答案

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

I fixed this issue by caching the element until touchend event is emitted. The pseudo code for the view that triggered the touchstart event would look something like this:

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
  }
}

这篇关于从dom中删除任何元素后,Touchmove事件将停止触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆