Touchmove event stops triggering after any element is removed from dom

后端 未结 1 2030
一个人的身影
一个人的身影 2021-01-06 02:06

On touch devices such as iPad (or mobile emulaton mode in chrome). When tracking touchmove event on body and removing an element (on which touc

相关标签:
1条回答
  • 2021-01-06 02:57

    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
      }
    }
    
    0 讨论(0)
提交回复
热议问题