在触摸设备上,如iPad(或chrome中的移动仿真模式)。当跟踪主体上的touchmove
事件并从dom中删除一个元素(在其上启动触摸启动)时,主体中的touchmove
事件停止触发。
我做了一个示例:http://jsbin.com/yinodosuxo/1/edit?js,控制台,输出
即使删除了子元素,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
}
}