在任何元素从dom中删除后触摸移动事件停止触发
问题描述:
在触摸设备上,例如iPad(或移动emulaton模式在chrome中)。当在身体上跟踪touchmove
事件并从身体停止触发事件中移除一个元素(在其上启动touchstart时)touchmove
。在任何元素从dom中删除后触摸移动事件停止触发
我做了一个例如: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
}
}